weblaf icon indicating copy to clipboard operation
weblaf copied to clipboard

JTabbedPane.SCROLL_TAB_LAYOUT can't work

Open lcy-1024 opened this issue 6 years ago • 3 comments

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

lcy-1024 avatar Nov 30 '20 12:11 lcy-1024

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:

  • With MetalLookAndFeel both sizes in your example are java.awt.Dimension[width=57,height=36]
  • With WebLookAndFeel both sizes in your example are java.awt.Dimension[width=450,height=38]

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

mgarin avatar Nov 30 '20 17:11 mgarin

thanks,it's worked now

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

lcy-1024 avatar Dec 04 '20 10:12 lcy-1024

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.

mgarin avatar Dec 07 '20 17:12 mgarin