• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Simple JPanel question....

 
Ranch Hand
Posts: 263
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
I am trying to write a simple Swing based Wizard. This is the approach.
I have a JFrame, to this i add 2 JPanels (one for each step of the wizard, assuming we only have 2 steps for now). I want to make one of them visible for each step of the wizard.
As long as i had only one JPanel, all was fine, but when i added two of these to the same location, and tried making one visible and rest invisible, i can't get it right.
Here is the code :

JFrame wizardFrame = new JFrame();
JPanel contentPane = new JPanel(new BorderLayout()); //The main JPanel, this is just a container for the panel1 and panel2
TestPanel1 testPanel1 = new TestPanel1();
contentPane.add(testPanel1, BorderLayout.CENTER);

TestPanel2 testPanel2 = new TestPanel2();
contentPane.add(testPanel2, BorderLayout.CENTER);
testPanel1.setVisible(true); //Initially First JPanel to be visible
testPanel2.setVisible(false); // When user clicks Next, i will make this as visible and tesPanel1 invisible
wizardFrame.setContentPane(contentPane);
wizardFrame.setSize(300,250);
wizardFrame.setVisible(true);
//I need to solve this of course. What am i doing wrong here ?
//I am new to Swing. Do you also suggest a be
 
Ranch Hand
Posts: 1143
1
Eclipse IDE Oracle Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Jitender,
I suggest you use a "CardLayout". See these Web pages for more details:
http://java.sun.com/j2se/1.4.1/docs/api/java/awt/CardLayout.html
http://java.sun.com/products/jfc/tsc/articles/cardpanel/index.html
Hope it helps.
Good Luck,
Avi.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic