Swing paint method not getting called

Sometimes when I run my application the paint method does not get called from the JPanel I set as my contentpane of my JFrame
5 Replies
JavaBot
JavaBot11mo ago
This post has been reserved for your question.
Hey @Noah | Nowipi! Please use /close or the Close Post button above when your problem is solved. Please remember to follow the help guidelines. This post will be automatically closed after 300 minutes of inactivity.
TIP: Narrow down your issue to simple and precise questions to maximize the chance that others will reply in here.
Noah | Nowipi
Noah | NowipiOP11mo ago
frame = new JFrame(title);
frame.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
frame.addKeyListener(new Keyboard());
frame.setSize(width, height);
frame.setResizable(resizable);
frame.setVisible(true);
frame.setContentPane(view);
view.setVisible(true);
System.out.println("set content pane");

public class View extends JPanel {

public View(int width, int height) {
super(true);
setPreferredSize(new Dimension(width, height));
}

@Override
public void paint(Graphics g) {
super.paint(g);

System.out.println("paint");
}
}
frame = new JFrame(title);
frame.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
frame.addKeyListener(new Keyboard());
frame.setSize(width, height);
frame.setResizable(resizable);
frame.setVisible(true);
frame.setContentPane(view);
view.setVisible(true);
System.out.println("set content pane");

public class View extends JPanel {

public View(int width, int height) {
super(true);
setPreferredSize(new Dimension(width, height));
}

@Override
public void paint(Graphics g) {
super.paint(g);

System.out.println("paint");
}
}
this is simplified code of what and when everything gets executed the console shows sometimes only 'set content pane' not paint the docs say the paint method gets called when you show a component so I tried doing so that's where the view.setVisible(true) comes from
Unknown User
Unknown User11mo ago
Message Not Public
Sign In & Join Server To View
Noah | Nowipi
Noah | NowipiOP11mo ago
that's still super weird it only hapens like 1 in 10 times and manually repaint calling didn't help but yeah I think that did it
JavaBot
JavaBot11mo ago
Post Closed
This post has been closed by <@270107388244262912>.
Want results from more Discord servers?
Add your server