我正在使用 Nimbus 的外观和感觉。根据此链接,您应该能够使用您的 JTree 实现 3 种不同的线条样式:
使用以下代码时:
theTree.putClientProperty("JTree.lineStyle", "Horizontal");
我的 JTree 看起来像这样:
它具有“无”样式而不是“水平”样式。知道为什么会这样吗?它与Nmbus有关吗?设置该属性后,我需要调用一些特殊的东西吗?
谢谢
我不相信 Nimbus 支持该JTree.lineStyle
属性。只有 MetalLookAndFeel 可以。
查看javax.swing.plaf.synth.SynthTreeUI
(Nimbus 使用) 和MetalTreeUI
(Metal 使用) 的源代码。
更改为 MetalLookAndFeel 并查看它是否有效。
事实证明,你可以通过这样做来获得一些这种效果
NimbusLookAndFeel laf = new NimbusLookAndFeel();
UIManager.setLookAndFeel(laf);
nimbUID = laf.getDefaults();
nimbUID.put("Tree.drawHorizontalLines", true);
nimbUID.put("Tree.drawVerticalLines", true);
不完美,但很接近。
对于仍然对此感兴趣的任何人:
以下代码段对我有用。
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
}