How to get JTabbedPane in JSplitPane to fill the whole window?

793 views Asked by At

My JTabbedPane is in a JSplitPane in a JPanel, like this, but I don't want it to be small like that:

enter image description here

I want it to look like this:

enter image description here

How do I do that?

Here is my code:

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

There are 2 answers

1
MadProgrammer On BEST ANSWER

Either add the JTabbedPanes directly to the JSplitPane

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

Or change the layout managers for left and right to BorderLayout

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

See How to Use BorderLayout for more details

1
A.K. On

use this code

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();
    }
}

you are not set frame size