import java.awt.Color; import java.awt.Container; import javax.swing.JFrame; import javax.swing.JLabel; import javax.swing.JPanel; import javax.swing.JTabbedPane; import javax.swing.SwingConstants; public class zengzhiwei01 extends JFrame { // public static void main(String agrs[]) { // System.out.println("hello world!"); // String agrs1[] = {"1","2","3"}; // for (int i = 0; i < agrs1.length; i++) { // System.out.println(agrs1[i]); // } // } private JTabbedPane tabbedPane; private JLabel label1,label2,label3; private JPanel panel1,panel2,panel3; public zengzhiwei01(){ super("选项卡窗口"); setSize(400,300); Container c = getContentPane(); tabbedPane = new JTabbedPane(); //创建选项卡面板界面 //创建标签 label1 = new JLabel("the first label panel",SwingConstants.CENTER); label2 = new JLabel("the secend label panel",SwingConstants.CENTER); label3 = new JLabel("the third label panel",SwingConstants.CENTER); //创建面板 panel1 = new JPanel(); panel2 = new JPanel(); panel3 = new JPanel(); panel1.add(label1); panel2.add(label2); panel3.add(label3); panel1.setBackground(Color.yellow); panel2.setBackground(Color.black); panel3.setBackground(Color.blue); //将标签面板加入到选项卡面板对象上 tabbedPane.addTab("标签1", null,panel1,"First panel"); tabbedPane.addTab("标签2", null, panel2, "Second panel"); tabbedPane.addTab("标签", null, panel3, "Third panel "); c.add(tabbedPane); c.setBackground(Color.white); setVisible(true); setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); } public static void main(String agrs[]){ zengzhiwei01 z = new zengzhiwei01(); } }
转载于:https://www.cnblogs.com/zzzzw/p/5220440.html