question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

JTabbedPane look and feel

See original GitHub issue

I am trying to create a JTabbedPane with a similar look to google chrome. like so:

image

I can get close by using tabbedPane.putClientProperty( "JTabbedPane.tabType", "card" );

image

I would also like to be able to round off the corners and remove the blue select bar. Is either option possible with flatlaf?

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:5

github_iconTop GitHub Comments

1reaction
DevCharlycommented, May 25, 2022

Regarding round edges: You can subclass FlatTabbedPaneUI and implement own painting.

grafik

public class MyFlatTabbedPaneUI
    extends FlatTabbedPaneUI
{
    public static ComponentUI createUI( JComponent c ) {
        return new MyFlatTabbedPaneUI();
    }

    @Override
    protected void paintCardTabBorder( Graphics g, int tabPlacement, int tabIndex, int x, int y, int w, int h ) {
        float lineWidth = UIScale.scale( 1f );
        float arc = UIScale.scale( 10 );
        
        Path2D path = new Path2D.Float( Path2D.WIND_EVEN_ODD );
        path.append( FlatUIUtils.createRoundRectanglePath( x, y, w, h, arc, arc, 0, 0 ), false );
        path.append( FlatUIUtils.createRoundRectanglePath( x + lineWidth, y + lineWidth, w - (lineWidth * 2), h - lineWidth,
            arc - lineWidth, arc - lineWidth, 0, 0 ), false );

        g.setColor( Color.red );
        ((Graphics2D)g).fill( path );
    }
}

Note: above code works only for “top” tab placement and needs some adjustments for other tab placements.

To use this for all tabbed panes, use:

UIManager.put( "TabbedPaneUI", MyFlatTabbedPaneUI.class.getName() );
UIManager.put( "TabbedPane.tabType", "card" );
UIManager.put( "TabbedPane.cardTabSelectionHeight", 0 );

Or for a single tabbed pane, use:

tabbedPane = new JTabbedPane() {
    @Override
    public void updateUI() {
        setUI( new MyFlatTabbedPaneUI() );
    }
};
tabbedPane.putClientProperty( "FlatLaf.style", "tabType: card; cardTabSelectionHeight: 0" );
0reactions
meeeee12commented, May 27, 2022

That did it. Thank you.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Java look and feel JTabbedPane - swing - Stack Overflow
The JTabbedPane is created before the PLAF is set. There are at least two fixes. ... There are a couple of UIManager settings...
Read more >
Customizing a JTabbedPane Look and Feel - Swing
Customizing a JTabbedPane Look and Feel : JTabbedPane « Swing « Java Tutorial · 1. First usage of JTabbedPane · 2. Adding and...
Read more >
JTabbedPane (Java Platform SE 7 ) - Oracle Help Center
A component that lets the user switch between a group of components by clicking on a tab with a given title and/or icon....
Read more >
Client Properties | FlatLaf - Flat Look and Feel - JFormDesigner
Specifies whether tabs are closable. If set to true on a tabbed pane component, all tabs in that tabbed pane are closable. To...
Read more >
JTabbedPane - Step by Step Programming - Google Sites
The shape of a tab and the way in which the selected tab is displayed varies by Look and Feel. JTabbedPane Source Code....
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found