JimmyWoodser
JimmyWoodser

Reputation: 121

JFrame Update problem

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

Answers (1)

objects
objects

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

Related Questions