如何在JSplitPane中获取JTabbedPane来填充整个窗口?

时间:2015-06-09 06:28:59

标签: java swing awt layout-manager

我的JTabbedPane位于JPanel的JSplitPane中,就像这样,但我不希望它像这样小:

enter image description here

我希望它看起来像这样:

enter image description here

我该怎么做?

这是我的代码:

Tabbed_Tables.java

public void setupWidow(){
        JPanel left = new JPanel();
        JPanel right = new JPanel();

        JTabbedPane EntryTabs =  new JTabbedPane();
        JTabbedPane ViewTabs =  new JTabbedPane();
        EntryTabs.addTab("Form Entry", new FormEntry());
        EntryTabs.setOpaque(true);
        EntryTabs.addTab("Table Entry", new TableEntry());
        //EntryTabs.setSize(new Dimension(500,500));
        //ViewTabs.setSize(new Dimension(200,200));
        ViewTabs.add("Help Window", new HelpWindow());


        left.add(EntryTabs);
        right.add(ViewTabs);

        JSplitPane splitPane= new JSplitPane(JSplitPane.HORIZONTAL_SPLIT,true,left, right);
        splitPane.setSize(new Dimension(pane.getWidth(),pane.getHeight()));
        //((JFrame) pane).setContentPane(splitPane);
        pane.add(splitPane,BorderLayout.CENTER);
        //this.setSize(500, 500);


        this.setVisible(true); 
        this.revalidate();
    }

2 个答案:

答案 0 :(得分:3)

JTabbedPane直接添加到JSplitPane

JSplitPane splitPane= new JSplitPane(JSplitPane.HORIZONTAL_SPLIT,true, EntryTabs, ViewTabs);

或者将leftright的布局管理器更改为BorderLayout

JPanel left = new JPanel(new BorderLayout());
JPanel right = new JPanel(new BorderLayout());

有关详细信息,请参阅How to Use BorderLayout

答案 1 :(得分:0)

使用此代码

import java.awt.*;
import javax.swing.*;
class MyLayout extends JFrame
{
    JPanel p1,p2;
    JTabbedPane jtp;
    public MyLayout()
    {
        setTitle("Tabed pane example");
        setSize(750,400);
        setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

        p1 = new JPanel();
        p2 = new JPanel();

        jtp = new JTabbedPane(JTabbedPane.TOP);
        jtp.addTab("Table Entry",p1);
        jtp.addTab("Chart Entry",p2);
        add(jtp);

        setVisible(true);

    }
    public static void main(String args[])
    {
        MyLayout m = new MyLayout();
    }
}

您未设置帧大小