tags:

views:

173

answers:

1

Please, help! How can I update my JFrame content(add new JPanel, add button, etc) after some action take place, like press button? Thanks!

+2  A: 

You add the new components the same way you add them when you first create the gui eg.

existingPanel.add(new JLabel("New Label"));

Then once added you tell the container that you added to that new stuff has been added by calling revalidate(). This allows it to layout its child components according to its layout manager

existingPanel.revalidate();
objects
to have that performed on a button client you would do it in the actionPerformed() method of the buttons ActionListener
objects
what about pack()? Will this also suffice?
Sylar
pack() is different, it adjusts the *frame* size to meet the preferred size of the components it contains. Not necessary and can be a little disconcerting to the user when the size of their window suddenly changes.
objects