Nimbus L&F 在 JTabbedPane 设置为滚动时缺少分隔线

发布于 2024-12-16 01:33:34 字数 1091 浏览 3 评论 0原文

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

在此处输入图像描述

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

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

//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 和 WRAP 。滚动。有人可以告诉我 .put() 有什么魔力才能到达那里吗?

提前致谢!

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!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

¢好甜 2024-12-23 01:33:35

可能涉及的对象:

一位同事发现了问题的根源。在:

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,分隔线实际上会显示,但被破坏了(内容的边框太厚,总体上不够长。

覆盖从 Synth 到 Nimbus 的所有内容将需要相当多的努力,因为有很多最终和 。

因此,您可能想要采取更简单的方法:

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

这将去除选项卡的下部间隙,并且您可以在内容面板的顶部边缘放置一个“假”分隔符,这就是我们处理的方式 不过,

希望它有帮助。

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!

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文