user1992697
user1992697

Reputation: 315

Refreshing JPanel to a new one

Is it possible to have a frame where by a new panel in that frame refreshes to the next panel, if you click the 2 link for example.

Is there easy code for this?

The picture below illustrates this better.

enter image description here

Upvotes: 2

Views: 85

Answers (2)

Praneeth Pj
Praneeth Pj

Reputation: 351

try this,

            MainPanel.revalidate();
            MainPanel.add(SecondPanel);
            MainPanel.revalidate();
            firstPanel.setVisible(false);
            SecondPanel.setVisible(true);
            validate();

Upvotes: 1

MadProgrammer
MadProgrammer

Reputation: 347314

You'll want to use a CardLayout, this is what it's designed for. It will allow you to switch out different components based on your needs

Check out How to use CardLayout for more info

Is there easy code for this?

That's a little subjective, but I would say CardLayout is the simplest of the possible solitons

Upvotes: 4

Related Questions