public class Test extends JFrame {
  JPanel jPanel1 = new JPanel();
  JButton jButton1 = new JButton();
  JButton jButton2 = new JButton();
  JButton jButton3 = new JButton();
  JButton jButton4 = new JButton();  public static void main(String[] args){
    Test t = new Test();
    t.setLocation(20,50);
    t.setSize(200,200);
    t.setVisible(true);
  }  public Test() {
    jPanel1.setLayout(new CardLayout());
    jButton1.setText("jButton1");
    jButton2.setText("jButton2");
    jButton3.setText("jButton3");
    jButton4.setText("jButton4");
    this.getContentPane().add(jPanel1, BorderLayout.CENTER);
    jPanel1.add(jButton1,  "jButton1");
    jPanel1.add(jButton2,  "jButton2");
    jPanel1.add(jButton3,  "jButton3");
    jPanel1.add(jButton4,  "jButton4");
  }
}

解决方案 »

  1.   

    不知道我的说法对不对,是这种效果:http://vip.6to23.com/wocienyoung/my/pp.jpg
      

  2.   

    应该叫 JTabbedPane
    用 JB 简单的画了一个 你先看看吧import javax.swing.*;
    import java.awt.*;
    import java.awt.event.*;public class Frame1 extends JFrame {
      int count;
      JTabbedPane jTabbedPane1 = new JTabbedPane();
      JButton jButton1 = new JButton();  public static void main(String[] args){
        Frame1 t = new Frame1();
        t.setLocation(50,30);
        t.setSize(500,200);
        t.show();
      }
      public Frame1() {
        try {
          jbInit();
        } catch(Exception e) {
          e.printStackTrace();
        }
      }  private void jbInit() throws Exception {
        jButton1.setText("Click me to add new JTabbedPane");
        jButton1.addActionListener(new java.awt.event.ActionListener() {
          public void actionPerformed(ActionEvent e) {
            jButton1_actionPerformed(e);
          }
        });
        this.getContentPane().add(jTabbedPane1, BorderLayout.CENTER);
        this.getContentPane().add(jButton1, BorderLayout.NORTH);    this.jTabbedPane1.add(new Button((new Integer(count++)).toString()));
      }  void jButton1_actionPerformed(ActionEvent e) {
        this.jTabbedPane1.add(new Button((new Integer(count++)).toString()));
      }}