1

I'm quite new to Java, and right now I'm playing around with GUI. I now have a JFrame - lets call it page1 - with a bit of content (text, images etc). So what I want to do is to create several such "pages" with different content, and be able to switch between these pages within my program.

So my question is, what's the best way to do this? Say I want to create a page2 with different images and text, what should I be looking at to make that happen?

I hope this is somewhat understandable. I just need to be pushed in the right direction so I know what to dig into.

Maroun
  • 94,125
  • 30
  • 188
  • 241
Boxiom
  • 2,245
  • 6
  • 40
  • 51
  • Look for `CardLayout` - If I understood your question, you'll understand my comment. – Maroun Jun 25 '13 at 17:15
  • Your question isn't clear, but since you mention pages, I'm guessing you want to create a wizard. Take a look at Oracle's guide to wizards. http://www.oracle.com/technetwork/articles/javase/wizard-136789.html – Gilbert Le Blanc Jun 25 '13 at 17:15
  • See [this](http://stackoverflow.com/questions/14011397/how-to-add-jpanel-by-clicking-jbutton/14012757#14012757) example of CardLayout (near the bottom of the answer) – David Kroukamp Jun 25 '13 at 18:44

1 Answers1

5

You may want to use CardLayout . Here is a tutorial how to use CardLayout

Example :

//Where instance variables are declared:
JPanel cards;
final static String BUTTONPANEL = "Card with JButtons";
final static String TEXTPANEL = "Card with JTextField";

//Where the components controlled by the CardLayout are initialized:
//Create the "cards".
JPanel card1 = new JPanel();
...
JPanel card2 = new JPanel();
...

//Create the panel that contains the "cards".
cards = new JPanel(new CardLayout());
cards.add(card1, BUTTONPANEL);
cards.add(card2, TEXTPANEL);
nachokk
  • 14,363
  • 4
  • 24
  • 53