tags:

views:

48

answers:

2

I want to add some new Components to my JFrame while runtime when pressing a button. This works so far, but i have to resize the window by hand to see the new components! is there any Action i can fire or a method to call to refresh the window?

A: 

you have to revalidate(); the frame. If that aint enough you also have to call repaint();

ymene
ok had to hack a little bit arround in my classes but it works! (btw you did mean validate() right? ;))
reox
indeed, since JFrame is already a top level container, you just can call validate();.
ymene
Well, generally components are added to a JPanel, not the frame directly, so you would revalidate the panel.
camickr
oh that makes everything more simpler, thanks!
reox
A: 

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