Måske skulle du studere de forskellige LayoutManager's:
http://java.sun.com/docs/books/tutorial/uiswing/layout/index.htmlDu får lige et eksempel på CardLayout, én JFrame og 3 JPanels, måske er det noget du kan bruge - synes selv det rimeligt at gå til.
import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
public class TestCardLayout extends JFrame {
public TestCardLayout() {
initComponents();
setSize(400,400);
}
private void initComponents() {
jPanel1 = new JPanel();
jLabel1 = new JLabel();
jPanel2 = new JPanel();
jPanel3 = new JPanel();
jPanel4 = new JPanel();
jPanel5 = new JPanel();
jMenuBar1 = new JMenuBar();
jMenu1 = new JMenu();
jMenuItem1 = new JMenuItem();
jMenuItem2 = new JMenuItem();
jMenuItem3 = new JMenuItem();
addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent evt) {
exitForm(evt);
}
});
jLabel1.setText("I dette panel er en masse knapper og tekstfelter");
jPanel1.add(jLabel1);
getContentPane().add(jPanel1, BorderLayout.NORTH);
jPanel2.setLayout(new CardLayout());
jPanel3.setBackground(new Color(0, 102, 255));
jPanel2.add(jPanel3, "card2");
jPanel4.setBackground(new Color(255, 0, 51));
jPanel2.add(jPanel4, "card3");
jPanel5.setBackground(new Color(51, 153, 0));
jPanel2.add(jPanel5, "card4");
getContentPane().add(jPanel2, BorderLayout.CENTER);
jMenu1.setText("Menu");
jMenuItem1.setText("Vis bl\u00e5t panel");
jMenuItem1.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent evt) {
action1(evt);
}
});
jMenu1.add(jMenuItem1);
jMenuItem2.setText("Vis r\u00f8dt panel");
jMenuItem2.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent evt) {
action2(evt);
}
});
jMenu1.add(jMenuItem2);
jMenuItem3.setText("Vis gr\u00f8nt panel");
jMenuItem3.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent evt) {
action3(evt);
}
});
jMenu1.add(jMenuItem3);
jMenuBar1.add(jMenu1);
setJMenuBar(jMenuBar1);
pack();
}
private void action1(ActionEvent evt) {
CardLayout cl = (CardLayout)jPanel2.getLayout();
cl.show(jPanel2, "card2");
}
private void action2(ActionEvent evt) {
CardLayout cl = (CardLayout)jPanel2.getLayout();
cl.show(jPanel2, "card3");
}
private void action3(ActionEvent evt) {
CardLayout cl = (CardLayout)jPanel2.getLayout();
cl.show(jPanel2, "card4");
}
private void exitForm(WindowEvent evt) {
System.exit(0);
}
public static void main(String args[]) {
new TestCardLayout().show();
}
private JLabel jLabel1;
private JMenu jMenu1;
private JMenuBar jMenuBar1;
private JMenuItem jMenuItem1;
private JMenuItem jMenuItem2;
private JMenuItem jMenuItem3;
private JPanel jPanel1;
private JPanel jPanel2;
private JPanel jPanel3;
private JPanel jPanel4;
private JPanel jPanel5;
}