Wizard-Like application

Hi.

I am writing a swing-based application. The program consists of the following classes:

1- MainClass (JFrame)

2- PanelA (JPanel)

3- PanelB (JPanel)

4- PanelC (JPanel)

The MainClass constructor creates a JPanel for the buttons 'next' and 'back' and adds them to the southern region of the MainClass. It also creates and adds the PanelA object 'a' to the center of MainClass.

When the 'next' button is clicked, the program determines whether an instance of the required panel already exists. If it exists, the method 'attachToCenter' is called. If it doesn't exist, it is created bofore calling 'attachToCenter' method. Here's the code for this method:

publicvoid attachToCenter(JPanel panel)

{

if (currentPanel.equals("a"))

{

this.getContentPane().remove(a);// PanelA a = new PanelA();

}

elseif (currentPanel.equals("b"))

{

this.getContentPane().remove(b);// PanelB b = new PanelB();

}

elseif (currentPanel.equals("c"))

{

this.getContentPane().remove(c);// PanelC c = new PanelC();

}

this.getContentPane().add(panel, BorderLayout.CENTER);

validate();

}

The same method is used for the 'back' buttaon as well.

Now, when the 'next, button is clicked and a new instance of one of the above-mentioned panels is created, and 'attachToCenter' is called, everything works fine. But when 'back' button is clicked,

the panels are switched, but the display is not updated until I minimize and then restore the MainClass (JFrame). Same problem continues to occur even when clicking 'next' button after that.

Please help me out.

Thank you.

Shakeel.

[2372 byte] By [JShaqa] at [2007-11-26 19:34:45]
# 1
currentPanel.revalidate();or my old foolish way ;pcurrentPanel().setVisible(false);currentPanel().setVisible(true);Message was edited by: Icycool
Icycoola at 2007-7-9 22:08:46 > top of Java-index,Desktop,Core GUI APIs...
# 2
Maybe use a [url http://java.sun.com/docs/books/tutorial/uiswing/layout/visual.html]Card Layout[/url]
camickra at 2007-7-9 22:08:46 > top of Java-index,Desktop,Core GUI APIs...
# 3
Thanks. I'll try it out.Shakeel.
JShaqa at 2007-7-9 22:08:46 > top of Java-index,Desktop,Core GUI APIs...
# 4
http://www.java2s.com/Code/Java/Swing-Components/Wizard.htmthis may help you
b.m.krajua at 2007-7-9 22:08:46 > top of Java-index,Desktop,Core GUI APIs...