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
2010-03-03 07:48:56
to have that performed on a button client you would do it in the actionPerformed() method of the buttons ActionListener
objects
2010-03-03 07:50:11
what about pack()? Will this also suffice?
Sylar
2010-03-03 08:05:22
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
2010-03-03 08:14:00