Omp*_*pie 5 java swing jtabbedpane nimbus
我在设置为 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 ...
Run Code Online (Sandbox Code Playgroud)
我似乎无法弄清楚 Nimbus 在何处以及如何区分 WRAP 和 SCROLL。有人可以告诉我我必须使用什么魔法.put()才能到达那里吗?
提前致谢!
敬启者:
一位同事找到了问题的根源。在:
package javax.swing.plaf.synth.SynthTabbedPaneUI;
Run Code Online (Sandbox Code Playgroud)
它说:
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);
}
Run Code Online (Sandbox Code Playgroud)
正如您所看到的,scrollableTabLayout 被排除在计算分隔符大小的以下代码之外。当您按照括号操作时,您会看到:尽管如此,它后来还是被绘制了,但是参数错误。如果选项卡设置在内容的顶部或左侧,这会导致分隔符被省略的行为。如果设置为 RIGHT 或 BOTTOM,分隔线实际上会显示,但已损坏(内容边框太厚,总体不够长。
覆盖从 Synth 到 Nimbus 的所有内容需要相当多的努力,因为有很多最终的和受包保护的类。
因此,您可能想要采取更简单的路线:
uiDefaults.put("TabbedPane:TabbedPaneTabArea.contentMargins", new InsetsUIResource(3, 10, 0, 10));
Run Code Online (Sandbox Code Playgroud)
这将消除选项卡的下部间隙,并且您可以在内容面板的顶部边缘放置一个“假”分隔线。不过,这就是我们处理它的方式。
希望能帮助到你。享受!
| 归档时间: |
|
| 查看次数: |
1470 次 |
| 最近记录: |