24

I want to add some new Components to my JFrame during runtime when a button is pressed. This works so far, but i have to resize the window manually to see the new components.

Is there any Action I can fire or a method to call to refresh the window? Any help appreciated. Thanks in advance.

Anonymous Penguin
  • 2,027
  • 4
  • 34
  • 49
reox
  • 5,036
  • 11
  • 53
  • 98

3 Answers3

43

You have to revalidate(); the frame. If that doesn't work you also have to call repaint();

Mikhail
  • 7,749
  • 11
  • 62
  • 136
crusam
  • 6,140
  • 6
  • 40
  • 68
9

Call

revalidate();
repaint();

revalidate tells the layout manager to reset based on the new component list. This will also trigger a call to repaint.

repaint is used to tell a component to repaint itself.

dogbane
  • 266,786
  • 75
  • 396
  • 414
0

in java repaint(); working for me. while revalidate(); not working for me.

A.YULGHUN
  • 11
  • 2