7

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

在此处输入图像描述

使用以下代码时:


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

我的 JTree 看起来像这样:

在此处输入图像描述

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

谢谢

4

3 回答 3

6

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

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

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

于 2011-02-18T15:30:17.803 回答
5

事实证明,你可以通过这样做来获得一些这种效果

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

不完美,但很接近。

于 2012-04-28T18:00:57.440 回答
1

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

以下代码段对我有用。

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
}
于 2014-12-01T22:11:26.063 回答