【问题标题】:Nimbus L&F missing divider at JTabbedPane set to scrollJTabbedPane 上的 Nimbus L&F 缺少分隔线设置为滚动
【发布时间】:2011-12-31 07:11:10
【问题描述】:

我缺少选项卡和 Nimbus L&F TabbedPane 中设置为 SCROLL 的内容之间的蓝色水平分隔线(其他 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 和 SCROLL。有人可以告诉我.put() 需要什么魔法才能到达那里吗?

提前致谢!

【问题讨论】:

  • +1 很好,你能回答这个问题吗stackoverflow.com/q/7481991/714968
  • 感谢您的信任,但我不知道该怎么做。不过,我看了看,没有发现任何问题。尝试解决此问题的人可能会从您在问题中发布的 SSCCE 中受益。谢谢!

标签: java swing jtabbedpane nimbus


【解决方案1】:

可能涉及的人员:

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

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 的所有内容需要付出相当大的努力,因为有很多 final 和受包保护的类。

因此,您可能想采取更简单的路线:

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

这将剥离标签的下部间隙,您可以在内容面板的顶部边缘放置一个“假”分隔线。不过,这就是我们处理它的方式。

希望对您有所帮助。享受吧!

【讨论】:

  • 如果有人提出更好/更简单的解决方案,我将切换“正确答案”标志。
猜你喜欢
  • 2015-12-21
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2018-02-07
  • 2012-08-01
  • 1970-01-01
相关资源
最近更新 更多