For example, if i had created 3 panel (JPanelA, JPanelB and JPanelC), 1 JFrame ,1 JButton(JButton1) in JPanelA and 1 JButton(JButton2).

Firstly, when I run the application, the screen will display JPanelA in JFrame. When I click on JButton1 in JPanelA, the JPanelA will be removed and JPanelB will be added into the JFrame. And when I click the JButton2 in JPanel2, the JPanelB will be removed and JPanelC will be added into the JFrame. Also vice-versa.

Please show me an example on how to code this and I need it urgently for my project. Thank you.

If I had double post the same question again, please send me the link to that thread thanks and I will delete this.

11-25-2010, 04:24 PM

Fubarable

Hello weikang, what I think you want to use is a CardLayout, and you will find a great tutorial on this with sample code here: The CardLayout

I would recommend that you have the JFrame's contentPane use the CardLayout for it's layout, and then you could have your JButtons simply call the CardLayout object's next method if you want the GUI to display the next panel in the series. I think that next(Container) will automatically go back to the first JPanel if it is called when the last component is visible. Also be sure to pass the contentPane into this method as its argument.

Luck!

11-26-2010, 01:58 AM

weikang

Thank you.

But if I did not want to use CardLayout method, what other method can I use.