给你一种接近的方式,看看合适吗?
package test;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTabbedPane;
public class ChangePanel {
public static void main(String[] args) {
JTabbedPane tab = new JTabbedPane();
JPanel p1 = new JPanel();
p1.add(new JLabel("p1"));
JPanel p2 = new JPanel();
p2.add(new JLabel("p2"));
JPanel p3 = new JPanel();
p3.add(new JLabel("p3"));
tab.insertTab("p1", null, p1, null, 0);
tab.insertTab("p2", null, p2, null, 1);
tab.insertTab("p3", null, p3, null, 2);
JFrame frame = new JFrame("TabPanel");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.getContentPane().add(tab);
frame.pack();
frame.setVisible(true);
}
}