JTree 线条样式和 Nimbus

发布于 2024-10-17 19:33:19 字数 518 浏览 4 评论 0原文

我正在使用 Nimbus 的外观和感觉。根据这个链接,您应该能够实现JTree 具有 3 种不同的线条样式:

在此处输入图像描述

使用以下代码时:


theTree.putClientProperty("JTree.lineStyle", "Horizontal");

我的 JTree 如下所示:

在此处输入图像描述

它具有“无”样式,而不是“水平”样式。知道为什么会这样吗?和Nmbus有关系吗?设置该属性后我需要调用一些特殊的东西吗?

谢谢

I am using the Nimbus look and feel. According to this link, you should be able to achieve 3 different line styles with your JTree:

enter image description here

While using the following code:


theTree.putClientProperty("JTree.lineStyle", "Horizontal");

My JTree looks like this:

enter image description here

It has the "None" style and not the "Horizontal" style. Any idea why this might be? Does it have something to do with Nmbus? Do I need to call something special after setting that property?

Thanks

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

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

发布评论

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

评论(3

合久必婚 2024-10-24 19:33:19

我不相信 Nimbus 支持 JTree.lineStyle 属性。只有 MetalLookAndFeel 可以。

查看 javax.swing.plaf.synth.SynthTreeUI(由 Nimbus 使用)和 MetalTreeUI(由 Metal 使用)的源代码。

更改为 MetalLookAndFeel 并查看是否有效。

I don't believe Nimbus supports the JTree.lineStyle property. Only the MetalLookAndFeel does.

Take a look at the source code for javax.swing.plaf.synth.SynthTreeUI (which is used by Nimbus) and MetalTreeUI (which is used by Metal).

Change to MetalLookAndFeel and see if it works.

一曲琵琶半遮面シ 2024-10-24 19:33:19

事实证明,您可以通过执行“不完美,但接近”来获得一些这种效果

NimbusLookAndFeel laf = new NimbusLookAndFeel();
UIManager.setLookAndFeel(laf);
nimbUID = laf.getDefaults();
nimbUID.put("Tree.drawHorizontalLines", true);
nimbUID.put("Tree.drawVerticalLines", true);

Turns out you can get some of this effect by doing

NimbusLookAndFeel laf = new NimbusLookAndFeel();
UIManager.setLookAndFeel(laf);
nimbUID = laf.getDefaults();
nimbUID.put("Tree.drawHorizontalLines", true);
nimbUID.put("Tree.drawVerticalLines", true);

Not perfect, but close.

混吃等死 2024-10-24 19:33:19

对于仍然对此感兴趣的人:

以下代码片段对我有用。

NewNimbusLookAndFeel laf = new NewNimbusLookAndFeel();

UIDefaults defs = laf.getDefaults();
defs.put("Tree.drawHorizontalLines", true);
defs.put("Tree.drawVerticalLines", true);
defs.put("Tree.linesStyle", "dashed");

try {
    UIManager.setLookAndFeel(laf);
} catch (UnsupportedLookAndFeelException e) {
    //Error handling code
}

For anyone still interested in this:

The following snippet is working for me.

NewNimbusLookAndFeel laf = new NewNimbusLookAndFeel();

UIDefaults defs = laf.getDefaults();
defs.put("Tree.drawHorizontalLines", true);
defs.put("Tree.drawVerticalLines", true);
defs.put("Tree.linesStyle", "dashed");

try {
    UIManager.setLookAndFeel(laf);
} catch (UnsupportedLookAndFeelException e) {
    //Error handling code
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文