Swap panes
Hi everybody, Im new here and I hope I can solve all my doubts ;).
About this,
The main Frame has a JPanel (panel) ,2 JButton (button1 & button2)
I have also in the same project tow classes more: Panel1 and Panel2 (they are JPanel).
What i want to do is the following:
- When I click in button1 the content of panel should be the content of Panel1
- When I click in button2 the content of panel should be the content of Panel2.
How can I do this? Thanks in advance
[519 byte] By [
naskara] at [2007-11-26 13:37:13]

One way is to add an action listener to the buttons.
So it would look something down this line...
button1.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
Panel1 panel = new JPanel1(); // or whatever other constructor sig you have for Panel1
Frame.this.add(panel); // or whatever name of the class that main is in...which I assume extends JFrame?
}
});
> One way is to add an action listener to the buttons.
>
> So it would look something down this line...
>
> > button1.addActionListener(new ActionListener() {
>public void actionPerformed(ActionEvent e) {
> Panel1 panel = new JPanel1(); // or whatever other
> constructor sig you have for Panel1
> Frame.this.add(panel); // or whatever name of the
> class that main is in...which I assume extends
> JFrame?
> }
> );
>
I proved that way but it doesnt work for me.
In the constructor of the main frame I do:
private Panel1 panel1;
private Panel2 panel2;
...
panel1=new Panel1();
panel2=new Panel2();
And the action listener for button1 is:
panel=panel1;
But it does not work...
I磍l take a glance to the card layout tutorial.
Sorry, I dont see the swing forum, my mistake ;).
Thanks ;)