mgarin / weblaf

WebLaF is a fully open-source Look & Feel and component library written in pure Java for cross-platform desktop Swing applications.
http://weblookandfeel.com
GNU General Public License v3.0
1.14k stars 235 forks source link

JTabbedPane.SCROLL_TAB_LAYOUT can't work #657

Closed lcy-1024 closed 3 years ago

lcy-1024 commented 3 years ago
public static void main(String[] args) {
    SwingUtilities.invokeLater(() -> {
        // WebLookAndFeel.install();

        JPanel left = new JPanel();
        JTabbedPane right = new JTabbedPane(JTabbedPane.TOP, JTabbedPane.SCROLL_TAB_LAYOUT);
        for (int i = 0; i < 10; i++) {
            right.add("Tab " + i, new JPanel());
        }

        JSplitPane jSplitPane = new JSplitPane();
        jSplitPane.setLeftComponent(left);
        jSplitPane.setRightComponent(right);

        JFrame jFrame = new JFrame();
        jFrame.add(jSplitPane);
        jFrame.setSize(800, 600);
        jFrame.setLocationRelativeTo(null);
        jFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        jFrame.setVisible(true);
    });
}
mgarin commented 3 years ago

What exactly doesn't work? It does seem to work correctly for me on v1.2.13.

If you mean that you can't shrink JTabbedPane within JSplitPane - this is because WebLaF calculates JTabbedPane minimum and preferred sizes differently:

This difference is there because WebLaF accounts for tab sizes while MetalLookAndFeel and probably some other L&Fs don't.

Difference between L&Fs aside - if you want to have any component within either of JSplitPane sides "shrinkable" - you might want to force at least it's minimum size to either zero or some specific value suitable for you.

On the example you provided:

public static void main ( final String[] args )
{
    SwingUtilities.invokeLater ( new Runnable ()
    {
        @Override
        public void run ()
        {
            WebLookAndFeel.install ();

            final JPanel left = new JPanel ();
            final JTabbedPane right = new JTabbedPane ( JTabbedPane.TOP, JTabbedPane.SCROLL_TAB_LAYOUT );
            for ( int i = 0; i < 10; i++ )
            {
                right.add ( "Tab " + i, new JPanel () );
            }
            right.setMinimumSize ( new Dimension ( 50, 50 ) );

            final JSplitPane jSplitPane = new JSplitPane ();
            jSplitPane.setLeftComponent ( left );
            jSplitPane.setRightComponent ( right );

            final JFrame jFrame = new JFrame ();
            jFrame.add ( jSplitPane );
            jFrame.setSize ( 800, 600 );
            jFrame.setLocationRelativeTo ( null );
            jFrame.setDefaultCloseOperation ( JFrame.EXIT_ON_CLOSE );
            jFrame.setVisible ( true );
        }
    } );
}

This way you can shrink the JTabbedPane area in your example:

image

lcy-1024 commented 3 years ago

thanks,it's worked now

right.setMinimumSize ( new Dimension ( 50, 50 ) );

mgarin commented 3 years ago

Since your problem is solved I'll close this issue. I've created a separate issue #660 for a small enhancement to JTabbedPane's minimum size.