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
2010-09-15 14:16:15
ok had to hack a little bit arround in my classes but it works! (btw you did mean validate() right? ;))
reox
2010-09-15 14:26:44
indeed, since JFrame is already a top level container, you just can call validate();.
ymene
2010-09-15 14:54:43
Well, generally components are added to a JPanel, not the frame directly, so you would revalidate the panel.
camickr
2010-09-15 15:33:43
oh that makes everything more simpler, thanks!
reox
2010-09-16 07:16:03
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
2010-09-15 14:20:47