我写了一个程序,是加入选项卡的,但是编译后运行时,选项卡的大小很小,请问怎样设置选项卡的大小 ,
让可以设置为指定尺寸,用setSize()这个方法行吗.
以下是我的代码,是选项卡的嵌套每个选项卡中都有一个选项卡,请部怎么才能设置它的尺寸
请高手回答,我这可是反根都给你们了,原码就在这.
import java.awt.*;
import javax.swing.*;public class Jtabbed

       JFrame frame=new JFrame("选项卡套用");
       JTabbedPane tabbed1=new JTabbedPane(JTabbedPane.LEFT);
       JTabbedPane tabbed2=new JTabbedPane();
        JTabbedPane tabbed3=new JTabbedPane();
       JTabbedPane tabbed4=new JTabbedPane();
       JPanel p1,p2,p3,p11,p12,p13,p21,p22,p23,p31,p32,p33;       public Jtabbed()
              {
                   Container cp=frame.getContentPane();
                    cp.setLayout(new FlowLayout());
                   p1=new JPanel();
                   p1.setBackground(Color.RED);
                   p2=new JPanel();
                   p2.setBackground(Color.GREEN);
                   p3=new JPanel();
                   p3.setBackground(Color.BLUE);
                   p11=new JPanel();    p11.setBackground(Color.WHITE);
                   p12=new JPanel();    p12.setBackground(Color.BLACK);
                   p13=new JPanel();    p13.setBackground(Color.YELLOW);
                   p21=new JPanel();    p21.setBackground(Color.RED);
                   p22=new JPanel();    p22.setBackground(Color.BLUE);
                   p23=new JPanel();    p23.setBackground(Color.YELLOW);
                   p31=new JPanel();    p31.setBackground(Color.GREEN);
                   p32=new JPanel();    p32.setBackground(Color.RED);
                   p33=new JPanel();    p33.setBackground(Color.YELLOW);                   tabbed2.addTab("红1",null,p11,"红色面板1");
                   tabbed2.addTab("红2",null,p12,"红色面板2");
                   tabbed2.addTab("红3",null,p13,"红色面板3");
                   tabbed3.addTab("绿1",null,p21,"绿色面板1");
                   tabbed3.addTab("绿2",null,p22,"绿色面板2");
                    tabbed3.addTab("绿3",null,p23,"绿色面板3");
                    tabbed4.addTab("蓝1",null,p31,"蓝色面板1");
                      tabbed4.addTab("蓝2",null,p32,"蓝色面板2");
                    tabbed4.addTab("蓝3",null,p33,"蓝色面板3");
                    p1.add(tabbed2);
                     p2.add(tabbed3);
                    p3.add(tabbed4);
                    tabbed1.addTab("红",null,p1,"红色面板");
                    tabbed1.addTab("绿",null,p2,"绿色面板");
                     tabbed1.addTab("蓝",null,p3,"蓝色面板");
                    cp.add(tabbed1);
                    frame.setBounds(200,200,300,300);
                    frame.setVisible(true);
                     
              frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
                  }
public static void main(String[] args)
{
       Jtabbed diao=new Jtabbed();
 }
}

解决方案 »

  1.   

    对楼主的问题:设置选项卡的大小,我自己也查找了一下api
    没有对选项卡大小的设置,只有设置相应索引的选项卡的布局,窗格组件等,
    并没有设置大小的方法,楼主的选项卡显示小可能是分辨率有关吧!
    以后的jdk也许就把这个漏洞补上了
      

  2.   

    这个你要看下你的布局管理器了   我改了一小下  你可以看看 其他的布局管理器的效果import java.awt.*; 
    import javax.swing.*; public class Jtabbed 

          JFrame frame=new JFrame("选项卡套用"); 
          JTabbedPane tabbed1=new JTabbedPane(JTabbedPane.LEFT); 
          JTabbedPane tabbed2=new JTabbedPane(); 
            JTabbedPane tabbed3=new JTabbedPane(); 
          JTabbedPane tabbed4=new JTabbedPane(); 
          JPanel p1,p2,p3,p11,p12,p13,p21,p22,p23,p31,p32,p33;       public Jtabbed() 
                  { 
                      Container cp=frame.getContentPane(); 
                        cp.setLayout(new BorderLayout()); 
                      p1=new JPanel(); 
                      p1.setBackground(Color.RED); 
                      p2=new JPanel(); 
                      p2.setBackground(Color.GREEN); 
                      p3=new JPanel(); 
                      p3.setBackground(Color.BLUE); 
                      p11=new JPanel();    p11.setBackground(Color.WHITE); 
                      p12=new JPanel();    p12.setBackground(Color.BLACK); 
                      p13=new JPanel();    p13.setBackground(Color.YELLOW); 
                      p21=new JPanel();    p21.setBackground(Color.RED); 
                      p22=new JPanel();    p22.setBackground(Color.BLUE); 
                      p23=new JPanel();    p23.setBackground(Color.YELLOW); 
                      p31=new JPanel();    p31.setBackground(Color.GREEN); 
                      p32=new JPanel();    p32.setBackground(Color.RED); 
                      p33=new JPanel();    p33.setBackground(Color.YELLOW);                   tabbed2.addTab("红1",null,p11,"红色面板1"); 
                      tabbed2.addTab("红2",null,p12,"红色面板2"); 
                      tabbed2.addTab("红3",null,p13,"红色面板3"); 
                      tabbed3.addTab("绿1",null,p21,"绿色面板1"); 
                      tabbed3.addTab("绿2",null,p22,"绿色面板2"); 
                        tabbed3.addTab("绿3",null,p23,"绿色面板3"); 
                        tabbed4.addTab("蓝1",null,p31,"蓝色面板1"); 
                          tabbed4.addTab("蓝2",null,p32,"蓝色面板2"); 
                        tabbed4.addTab("蓝3",null,p33,"蓝色面板3"); 
                        p1.add(tabbed2); 
                        p2.add(tabbed3); 
                        p3.add(tabbed4); 
                        tabbed1.addTab("红",null,p1,"红色面板"); 
                        tabbed1.addTab("绿",null,p2,"绿色面板"); 
                        tabbed1.addTab("蓝",null,p3,"蓝色面板"); 
                        cp.add(tabbed1,BorderLayout.CENTER); 
                        frame.setBounds(200,200,300,300); 
                        frame.setVisible(true); 
                        
                  frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); 
                      } 
    public static void main(String[] args) 

          Jtabbed diao=new Jtabbed(); 

    }
      

  3.   

    JTabbedPane作为容器是有大小的,运行了一下楼主的代码,如果楼主是想放大容器面板,可以在构造方法里加一句tabbed1.setPreferredSize(new Dimension(200,200));至于item的大小,是根据你的文字和用的图标来决定的,你可以设置一个指定大小的JLabel作为item,这样就可以控制item的大小了.