GridBagLayout in CardLayout....Problems

D

domenik.brugger

Hello,
i have a probleme with the cardLayout.

i have a jpanel with cardlayout and two cards in it with GridBagLayout.
In each card is a JButton. At a click there should be shown the next card with the other button.
But the buttons will be shown together when i start the program.

My Code:
Code:
package EP.GUI;
import static EP.UTIL.Sprache_DE.stRegeln;
import static java.awt.GridBagConstraints.BOTH;
import static java.awt.GridBagConstraints.LINE_START;
import static java.awt.GridBagConstraints.REMAINDER;

import java.awt.*;
import java.awt.event.*;

import javax.swing.*;


public class CardLayoutExample1 extends MyGridBagContraints{

private CardLayout cardLayout;
public JButton    button1, button2;
private JPanel     panel1, panel2, jPanelEigen, jPanelGridBag;



public CardLayoutExample1(){
super();

this.setSize(500,500);
this.setLayout(new GridBagLayout());
this.setVisible(true);
this.setLocation(50,50);
this.setTitle(stRegeln);
this.addWindowListener(new WindowListener() {
public void windowOpened(WindowEvent arg0) {}
public void windowIconified(WindowEvent arg0) {}
public void windowDeiconified(WindowEvent arg0) {}
public void windowDeactivated(WindowEvent arg0) {}
public void windowClosing(WindowEvent arg0) {

}
public void windowClosed(WindowEvent arg0) {}
public void windowActivated(WindowEvent arg0) {}
});

cardLayout = new CardLayout();
jPanelEigen = new JPanel(cardLayout);

panel1 = new JPanel(new GridBagLayout());
panel2 = new JPanel(new GridBagLayout());

button1 = new JButton("Button1");
button2 = new JButton("Button2");

jPanelEigen.add(getPanel1(), "card1");
jPanelEigen.add(getPanel2(), "card2");

cardLayout.show(jPanelEigen, "card1");
this.add(jPanelEigen);
pack();
createListener();
setVisible(true);
}

private JPanel getPanel1(){

panel1.setBackground(Color.gray);
setDefaultGB();
addGB(button1, gridx, gridy,
gridwidth = REMAINDER, gridheight, fill,
weightx, weighty, anchor,
insets);

return panel1;
}
private JPanel getPanel2(){

panel2.setBackground(Color.yellow);
setDefaultGB();
addGB(button2, gridx, gridy,
gridwidth = REMAINDER, gridheight, fill,
weightx, weighty, anchor,
insets);

return panel2;
}


private void createListener(){
ActionListener al = new ActionListener(){
public void actionPerformed(ActionEvent e){
cardLayout.next(jPanelEigen);
}
};
button1.addActionListener(al);
button2.addActionListener(al);

addWindowListener(new WindowAdapter(){
public void windowClosing(WindowEvent e){
System.exit(0);
}
});
}
}

I have no idea what to do and hope you can help me.
Thanks.
 
M

markspace

I have no idea what to do and hope you can help me.

I have no idea what to do either:
My Code:
Code:
package EP.GUI;
import static EP.UTIL.Sprache_DE.stRegeln; ^^^^^^^^^^^^^^^^^^^^^^^^^^^

public class CardLayoutExample1 extends MyGridBagContraints{[/QUOTE]
^^^^^^^^^^^^^^^^^^^


This doesn't help us.  Do you really think we can guess what is
happening when there are several methods in your code that you didn't
show us?  Please post something compiles, i.e., an SSCCE:

http://sscce.org/
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,007
Latest member
obedient dusk

Latest Threads

Top