• Post Reply Bookmark Topic Watch Topic
  • New Topic

JPanel not repainting

 
Haris Karameh
Ranch Hand
Posts: 38
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I do not use SWING a lot and I need help figuring this out:
Inside JFrame I added JSplitFrame which bottom part contains JPanel.
Now I want the panel dynamically populated with checkboxes after a button is pressed. Here is the code inside the panel which generates checkboxes:
...
private Box bx;

public MyPanel (){//this is the panel constructor extending JPanel
super();
initialize();
bx=new Box(BoxLayout.Y_AXIS);
add(bx);
}
...

public void populate(int start){
bx.removeAll()
remove(bx);
int sz=20;
for (int i=0;i<sz;i++){
bx.add(new JCheckBox( Integer.toString(start+i)));
}
add(bx);
}

Now, when the button is pushed for the first time everything is rendered ok. Pushing the button for the second time makes the panel blank, but if I resize the frame all new items appear. How do I make this "repaint" happen automatically after the box items have been replaced.
I tried addint invalidate and repaint into the different objects but it did not help.

TIA,
Haris
 
Haris Karameh
Ranch Hand
Posts: 38
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
After some digging I found the answer.
"validate()" should be called in JFrame to revaluate complete UI.
 
Haris Karameh
Ranch Hand
Posts: 38
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
After some digging I found the answer.
"validate()" should be called in JFrame to revaluate complete UI.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!