Nimbus L&F missing divider at JTabbedPane set to scroll

橙三吉。 提交于 2019-12-04 11:29:11

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!

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!