Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Nimbus L&F missing divider at JTabbedPane set to scroll

I am missing the blue horizontal divider between the tabs and the content in a Nimbus L&F TabbedPane set to SCROLL (other L&Fs (default & windows) provide those).

enter image description here

As you can see the problem is limited to new JTabbedPane(JTabbedPane.TOP, JTabbedPane.SCROLL_TAB_LAYOUT) (top of the picture) while the default with WRAP does not show this behaviour (bottom of the picture).

It should be possible to change something like this by overriding parts of the NimbusDefaults.class. Here is an excerpt:

//Initialize TabbedPane
    d.put("TabbedPane.contentMargins", new InsetsUIResource(0, 0, 0, 0));
    d.put("TabbedPane.tabAreaStatesMatchSelectedTab", Boolean.TRUE);
    d.put("TabbedPane.nudgeSelectedLabel", Boolean.FALSE);
    d.put("TabbedPane.tabRunOverlay", new Integer(2));
    d.put("TabbedPane.tabOverlap", new Integer(-1));
    d.put("TabbedPane.extendTabsToBase", Boolean.TRUE);
    d.put("TabbedPane.useBasicArrows", Boolean.TRUE);
    addColor(d, "TabbedPane.shadow", "nimbusDisabledText", 0.0f, 0.0f, 0.0f, 0);
    addColor(d, "TabbedPane.darkShadow", "text", 0.0f, 0.0f, 0.0f, 0);
    ... more ...

I just can't seem to figure out where and how Nimbus is distinguishing between WRAP & SCROLL. Could someone please tell me what magic I have to .put() to get there?

Thanks in advance!

like image 741
Omphaloskopie Avatar asked Nov 04 '22 11:11

Omphaloskopie


1 Answers

To whom it may concern:

A colleague found the source of the problem. In:

package javax.swing.plaf.synth.SynthTabbedPaneUI;

it says:

protected void paint(SynthContext context, Graphics g) {
    int selectedIndex = tabPane.getSelectedIndex();
    int tabPlacement = tabPane.getTabPlacement();

    ensureCurrentLayout();

// Paint tab area
// If scrollable tabs are enabled, the tab area will be
// painted by the scrollable tab panel instead.
//
if (!scrollableTabLayoutEnabled()) { // WRAP_TAB_LAYOUT

        [...]

        // Here is code calculating the content border

        [...]

    }

    // Paint content border
    paintContentBorder(tabContentContext, g, tabPlacement, selectedIndex);
}

As you can see the scrollableTabLayout is excluded from the following code where the size of the divider is calculated. As you follow the brackets you see: it later on is painted nevertheless, but with wrong params. This leads to the behaviour that the divider is omitted if the Tabs are set TOP or LEFT of the content. If set to RIGHT or BOTTOM the divider in fact is displayed, but broken (Border towards content too thick, overall not long enough.

It would take quite some efford to override everything from Synth to Nimbus because there are a heck of a lot final and package-protected classes.

Therefore you might want to take the easier route:

uiDefaults.put("TabbedPane:TabbedPaneTabArea.contentMargins", new InsetsUIResource(3, 10, 0, 10));    

This will strip the lower gap to your tabs and you may put a "fake" divider on the topper brink of your content-panel. Thats the way we handle it, though.

Hope it helps. Enjoy!

like image 91
Omphaloskopie Avatar answered Nov 15 '22 12:11

Omphaloskopie