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

Question: is close button for JTabbedPane available? #31

Closed
Gaulm opened this issue Jan 1, 2020 · 3 comments
Closed

Question: is close button for JTabbedPane available? #31

Gaulm opened this issue Jan 1, 2020 · 3 comments
Labels
enhancement New feature or request
Milestone

Comments

@Gaulm
Copy link

Gaulm commented Jan 1, 2020

As the title says I'm wondering if there is a function or property to display a close button near the title of a tabbed pane, like the one Intellij uses when you open many files.
It would be nice to have so that we don't have to deal with different LaFs.
Reference:
githubq

@DevCharly
Copy link
Collaborator

No, this is not yet implemented. Maybe in the future...

You could try following:

JPanel tab = new JPanel( new BorderLayout( 5, 0 ) );
tab.setOpaque( false );

JButton closeButton = new JButton( new FlatInternalFrameCloseIcon() );
closeButton.setContentAreaFilled( false );
closeButton.setBorder( null );
//TODO add action listener
tab.add( closeButton, BorderLayout.EAST );

tab.add( new JLabel( "Tab Title" ), BorderLayout.CENTER );

tabbedPane1.setTabComponentAt( 0, tab );

You could also try JideTabbedPane from JIDE Common Layer, which is supported by FlatLaf: https://github.com/JFormDesigner/FlatLaf/tree/master/flatlaf-jide-oss

@DevCharly DevCharly added the enhancement New feature or request label Jan 15, 2020
@swordmaster2k
Copy link

swordmaster2k commented Mar 30, 2020

I came across a similar need, and tried out your suggestion above. It worked very nicely in my case:

image

The only tweek I made was to set the max size of the button:

JButton closeButton = new JButton(new FlatInternalFrameCloseIcon());
closeButton.addMouseListener(new CloseListener(tab));
closeButton.setPreferredSize(new Dimension(16, 16));
closeButton.setMaximumSize(new Dimension(16, 16));
closeButton.setContentAreaFilled(false);
closeButton.setBorder(null);

Thank you!

@DevCharly DevCharly added this to the 0.44 milestone Oct 22, 2020
@DevCharly
Copy link
Collaborator

implemented in PR #193

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

3 participants