jpanel

Panel.repaint(); messes up layout

浪子不回头ぞ 提交于 2019-12-02 22:59:58
问题 JPanel Initiation p = new JPanel() { private static final long serialVersionUID = 1L; public void paintComponent(Graphics g) { if(errors == 1) g.drawOval(215, 50, 75, 75); else if(errors == 2) g.drawOval(200,200,200,200); } }; Method that calls repaint static void drawHead() { System.out.println("Head"); errors = 1; p.removeAll(); p.revalidate(); p.repaint(); } Before repaint my frame looks like this, http://i.imgur.com/XQlQeul.png And afterwards it looks like this, http://i.imgur.com/RnVuUzt

NullPointerException Error with JPanel and CardLayout

佐手、 提交于 2019-12-02 22:22:18
问题 I am working on hotel management software for class and I am running into a few issues with my code. At this point, I am simply trying to add a JPanel I created in a separate class into my main gui. Any Help would be greatly appreciated. ~ Thanks! Exception in thread "main" java.lang.NullPointerException at java.awt.Container.addImpl(Unknown Source) at java.awt.Container.add(Unknown Source) at hotelManage.HotelSystem.showGUI(HotelSystem.java:75) at hotelManage.HotelSystem.<init>(HotelSystem

Why repainting of that take so much time?

一个人想着一个人 提交于 2019-12-02 22:13:39
问题 I have something like that (the time is now displayed correctly). I have added KeyListener to the JFrame in which these JPanels are. When I press ->(right key) I want to time to increment by one and it does but it is really slow(like 3 seconds of waiting then even much longer). The algorithms in program are not the fault(checked without GUI, they're fast). Is there any way to faster the reaction ->pressing key-> changing time. The image is png so it should be fast. I call aktualizuj() every

Adding ChartPanel to jPanel not working

孤者浪人 提交于 2019-12-02 21:56:35
问题 I got this panel: public class StripchartPanel extends javax.swing.JPanel { public StripchartPanel() { XYSeries series = new XYSeries("XYGraph"); series.add(1, 1); series.add(1, 2); series.add(2, 1); series.add(3, 9); series.add(4, 10); // Add the series to your data set XYSeriesCollection dataset = new XYSeriesCollection(); dataset.addSeries(series); // Generate the graph JFreeChart chart = ChartFactory.createXYLineChart( "XY Chart", // Title "x-axis", // x-axis Label "y-axis", // y-axis

how to set the position of glasspane in JFrame?

我只是一个虾纸丫 提交于 2019-12-02 21:52:40
问题 I'm trying to create a menu slider from the left side of the frame. It need to be floating above the content, where i can access it always with a mouse listener(open the menu when the mouse is close to the left edge). Well, I set my GlassPane (My JPanel ) as setOpaue(false) and it was floating above the content. but the glasspane always positioned on the center, and I need to have a possibility to move it,slide it, but with no luck. the setBounds and setLocation does not worked for me. Can

Java Painting not working

巧了我就是萌 提交于 2019-12-02 21:41:53
问题 So I have this code: package tictactoe; import java.awt.Graphics; import java.awt.Graphics2D; import javax.swing.JFrame; import javax.swing.JPanel; public class TicTacToe extends JFrame { public static void main(String[] args) { JFrame masterFrame = new JFrame("TicTacToe"); JPanel drawingPanel = new JPanel(); GameBoard theGame = new GameBoard(); masterFrame.add(drawingPanel); masterFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); masterFrame.setSize(504, 504); masterFrame.setResizable

paintComponent is not being called in JPanel

耗尽温柔 提交于 2019-12-02 21:04:50
问题 I have following code: package hra; import java.awt.Color; import java.awt.EventQueue; import java.awt.Graphics; import java.awt.event.KeyEvent; import java.awt.event.KeyListener; import javax.swing.JFrame; import static javax.swing.JFrame.EXIT_ON_CLOSE; import javax.swing.JPanel; import javax.swing.UIManager; import javax.swing.UnsupportedLookAndFeelException; public class HerniPole extends JPanel implements KeyListener { public int velikostPole; HerniPole(int velikostPole) { this

JLabel only shows if initComponents() is deleted

蓝咒 提交于 2019-12-02 20:04:31
问题 MainFrame.java -JFrame public MainFrame() { initComponents(); Letters pl = new Letters(this); this.setContentPane(pl); this.setTitle("Preset Lessons"); this.pack(); } Letters.java -JPanel public Letters(JFrame frame) { initComponents(); JLabel label = new JLabel(); label.setText("Sample"); this.add(label); } if initComponents() in Letters.java is deleted thats the only time the JLabel will show up. How can I put the new JLabel to my existing JPanel? Contents of Letters.java's initComponents()

Java drawing on JPanel which on a JFrame [closed]

对着背影说爱祢 提交于 2019-12-02 19:59:03
问题 It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center. Closed 6 years ago . Hi I have a JFrame and there are two JPanels on top of it. My intention is to draw on the JPanels. Can anyone please share any Java code? 回答1: All the JComponents ( of which JPanel inherits from ) have a

Java Swing: JPanel only adds components when JFrame window is maximized or it's size changed

我是研究僧i 提交于 2019-12-02 19:37:31
问题 I have a Java program that creates a JFrame, a JPanel, and several JTextAreas. I set the text of the JTextAreas and then add them to the JPanel. When the program loads, I only see the empty JFrame. However, if I maximize, or change the size of the program window, the JTextAreas, and their respective texts appear on the screen. How can I correct this so that the program loads, with the text areas populated, without the need to mess with the window? My apologies in advance for being a Swing