Reputation: 121
Please, help! How can I update my JFrame content(add new JPanel, add button, etc) after some action take place, like press button? Thanks!
Upvotes: 2
Views: 2228
Reputation: 8677
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();
Upvotes: 2