I add a JButton to my JPanel subclass Quiz, and if I change either the text or the font of the button, the Quiz object disappears, showing only the panel underneath it. However, if I change the text or font before adding the button, everything works fine.
setupGraphics() gets called after the Quiz is added to the view hierarchy
public void setupGraphics() {
this.setBackground(Color.red);
setLayout(null);
a.setBounds(20, 20, 200, 200);
add(a);
a.setText("Hi");
}
If I change the code to this:
public void setupGraphics() {
this.setBackground(Color.red);
setLayout(null);
a.setBounds(20, 20, 200, 200);
a.setText("Hi");
add(a);
}
then it works.
Any ideas?