What constrains how much a divider can move in JSplitPane?

86 Views Asked by At

Have an application that uses a JSplitPane to divide a frame into top and bottom. I am having a problem that the divider only allows limited movement, preventing the bottom pane from being as large as I would like, and it is worse with some look and feels.

enter image description here

I have:

splitPane.setResizeWeight(0.0f);

The bottom pane should get priority on space. but it doesn't.

After frame is visible I get the values of min and max divider location, and this seems to match how much I can move the divider, but what decides these values?

ScreenLayout.getInstanceOf().getLayout().getMaximumDividerLocation());
ScreenLayout.getInstanceOf().getLayout().getDividerLocation()

It is better on Windows than MacOS, and on MacOS it works in a limited way with the standard Aqua Look and feel, but can only make smaller with FlatLaf look and feel

1

There are 1 best solutions below

1
Paul Taylor On

There seems to be a bug that JTabbedPane sets its minimum size based on summing up all the tabs height if they are JScrollPane, so the more tabs added the larger the minimum height of JTabbedPane, there doesn't seem to be an issue if add JTable directly to a JTabbedPane rather than a JTable wrapped in a JScrollPane but that is no use to me.

import com.formdev.flatlaf.FlatDarkLaf;

import javax.swing.*;
import javax.swing.plaf.basic.BasicLookAndFeel;
import java.io.File;

public class TabbedPaneTest
{
    public static void main(String[] args) throws Exception
    {
        try
        {
            JTabbedPane tabbedPane = new JTabbedPane();
            JTable t1 = new JTable(5,5);
            tabbedPane.addTab("", new JScrollPane(t1));
            JFrame frame = new JFrame();
            frame.add(tabbedPane);
            frame.pack();
            frame.setVisible(true);
            System.out.println(t1.getMinimumSize());
            System.out.println("scroll 1:"+tabbedPane.getComponentAt(0).getMinimumSize());
            System.out.println("TaBbedPane 1:"+tabbedPane.getMinimumSize());
        }
        catch(Exception ex)
        {
            ex.printStackTrace();
        }

        try
        {
            JTabbedPane tabbedPane = new JTabbedPane();
            JTable t1 = new JTable(5,5);
            tabbedPane.addTab("", new JScrollPane(t1));
            tabbedPane.addTab("", new JScrollPane(t1));
            tabbedPane.addTab("", new JScrollPane(t1));
            tabbedPane.addTab("", new JScrollPane(t1));
            tabbedPane.addTab("", new JScrollPane(t1));
            tabbedPane.addTab("", new JScrollPane(t1));
            tabbedPane.addTab("", new JScrollPane(t1));

            JFrame frame = new JFrame();
            frame.add(tabbedPane);
            frame.pack();
            frame.setVisible(true);
            System.out.println(t1.getMinimumSize());
            System.out.println("Scroll 1"+ tabbedPane.getComponentAt(0).getMinimumSize());
            System.out.println("Tabbed Pane 2"+tabbedPane.getMinimumSize());
        }
        catch(Exception ex)
        {
            ex.printStackTrace();
        }
    }
}

Outputs

java.awt.Dimension[width=75,height=80]
scroll 1:java.awt.Dimension[width=22,height=26]
TaBbedPane 1:java.awt.Dimension[width=27,height=54]
java.awt.Dimension[width=75,height=80]
Scroll 1java.awt.Dimension[width=22,height=22]
Tabbed Pane 2java.awt.Dimension[width=27,height=168]

If after creating JTabbedPane with tabs I hardcode setMinimumSize() the split pane works okay.