Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TabbedPane custom components on left and right sides of tabs area #192

Merged
merged 4 commits into from
Oct 20, 2020

Conversation

DevCharly
Copy link
Collaborator

@DevCharly DevCharly commented Oct 17, 2020

This PR introduces support for adding custom components to left and right sides of tabs area.

image

Set client properties JTabbedPane.leadingComponent or JTabbedPane.trailingComponent on a JTabbedPane to add components:

myTabbedPane.putClientProperty( "JTabbedPane.leadingComponent", new JButton( "Hello" ) );
myTabbedPane.putClientProperty( "JTabbedPane.trailingComponent", new JButton( "World" ) );

The preferred width of the added components is used, but the height is always set to the tab height.
Use an additional panel if your component should have a smaller height.

Edit: since commit dc92d09 the trailing component occupies all available horizontal space, which allows you to use all space on the right side of the tabs:

grafik

There is no gap between the leading/trailing components and the tabs.

If you want place buttons into the tab area, it is recommended to use a JToolBar:

image

(code from FlatLaf Demo)

JToolBar leading = new JToolBar();
leading.setFloatable( false );
leading.setBorder( null );
leading.add( new JButton( new FlatSVGIcon( "com/formdev/flatlaf/demo/icons/project.svg" ) ) );
myTabbedPane.putClientProperty( "JTabbedPane.leadingComponent", leading );

Because the trailing component occupies all available space, it is necessary to add a horizontal glue with javax.swing.Box.createHorizontalGlue() to the toolbar to get right aligned buttons:

JToolBar trailing = new JToolBar();
trailing.setFloatable( false );
trailing.setBorder( null );
trailing.add( new JButton( new FlatSVGIcon( "com/formdev/flatlaf/demo/icons/buildLoadChanges.svg" ) ) );
trailing.add( Box.createHorizontalGlue() );
trailing.add( new JButton( new FlatSVGIcon( "com/formdev/flatlaf/demo/icons/commit.svg" ) ) );
trailing.add( new JButton( new FlatSVGIcon( "com/formdev/flatlaf/demo/icons/diff.svg" ) ) );
trailing.add( new JButton( new FlatSVGIcon( "com/formdev/flatlaf/demo/icons/listFiles.svg" ) ) );
myTabbedPane.putClientProperty( "JTabbedPane.trailingComponent", trailing );

This is part of TabbedPane improvements as discussed in issue #40 (comment).

CC @smileatom @Chrriis

…of tabs area if "more tabs" button is used (issue #40)
…of tabs area if scroll backward/foreward buttons are used (issue #40)

this also fixes some minor layout issues when using tabAreaInsets and arrow buttons
@DevCharly DevCharly mentioned this pull request Oct 17, 2020
… components in calculating preferred/minimum size of tabbed pane, because the largest tab content determines the size
@DevCharly DevCharly added this to the 0.44 milestone Oct 17, 2020
@DevCharly DevCharly merged commit 8ccda81 into master Oct 20, 2020
@DevCharly DevCharly deleted the tabbedpane-custom-components branch October 20, 2020 07:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant