Search code examples
javaswinglook-and-feeljtabbedpanenimbus

Remove JTabbedPane border/divider in Nimbus Look and Feel


I use the Nimbus L&F, and I'm trying to remove the border shown on the picture below, as well as centering the tabs on my screen, similar to the default Mac OS look and feel. But I have still not had any success.

Help anyone?

http://bildr.no/image/cUJBdW94.jpeg


Solution

  • Not sure why you would even want to do this, but what you want to do is modify the defaults. You can see Nimbus Defaults for all of the default settings. If you scroll down the page, you will see all the defaults for TabbedPanes.

    enter image description here

    You can see all the painting of these default properties are done by a Painter. You can set the painter to null, so it won't paint anything.

    for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
        if ("Nimbus".equals(info.getName())) {
            UIManager.setLookAndFeel(info.getClassName());
            UIManager.getLookAndFeelDefaults().put(
                    "TabbedPane:TabbedPaneTabArea[Disabled].backgroundPainter", null);
            UIManager.getLookAndFeelDefaults().put(
                    "TabbedPane:TabbedPaneTabArea[Enabled+MouseOver].backgroundPainter", null);
            UIManager.getLookAndFeelDefaults().put(
                    "TabbedPane:TabbedPaneTabArea[Enabled+Pressed].backgroundPainter", null);
            UIManager.getLookAndFeelDefaults().put(
                    "TabbedPane:TabbedPaneTabArea[Enabled].backgroundPainter", null);
            break;
        }
    }
    

    enter image description here