JTabbedPane 上的 Nimbus L&F 缺少分隔符设置为滚动 [英] Nimbus L&F missing divider at JTabbedPane set to scroll

查看:33
本文介绍了JTabbedPane 上的 Nimbus L&F 缺少分隔符设置为滚动的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在设置为 SCROLL 的 Nimbus L&F TabbedPane 中的选项卡和内容之间缺少蓝色水平分隔线(其他 L&F(默认和窗口)提供这些).

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).

如您所见,问题仅限于 new JTabbedPane(JTabbedPane.TOP, JTabbedPane.SCROLL_TAB_LAYOUT)(图片顶部),而默认的 WRAP 不显示此行为(底部图片).

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).

应该可以通过覆盖 NimbusDefaults.class 的部分来更改类似的内容.摘录如下:

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 ...

我似乎无法弄清楚 Nimbus 在何处以及如何区分 WRAP 和滚动.有人能告诉我 .put() 有什么魔法才能到达那里吗?

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?

提前致谢!

推荐答案

可能涉及的对象:

一位同事找到了问题的根源.在:

A colleague found the source of the problem. In:

package javax.swing.plaf.synth.SynthTabbedPaneUI;

它说:

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);
}

如您所见,scrollableTabLayout 从以下计算分隔线大小的代码中排除.当您按照括号进行操作时,您会看到:尽管如此,它后来还是被绘制了,但是参数错误.如果将选项卡设置为内容的顶部或左侧,则会导致省略分隔符的行为.如果设置为 RIGHT 或 BOTTOM 分隔线实际上是显示的,但已损坏(内容的边框太粗,整体不够长.

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.

覆盖从 Synth 到 Nimbus 的所有内容需要相当多的努力,因为有很多最终和包保护的类.

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.

希望有帮助.享受!

这篇关于JTabbedPane 上的 Nimbus L&F 缺少分隔符设置为滚动的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆