2011-02-18 59 views
6

我使用的是Nimbus的外观和感觉。根据这一link,你应该能够实现3种不同的线条样式与您的JTree:JTree线条样式和Nimbus

enter image description here

在使用下面的代码:

 

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

我的JTree看起来是这样的:

enter image description here

它具有“无”风格而不是“水平”风格。任何想法,为什么这可能是?它与Nmbus有什么关系?设置该属性后,是否需要调用特别的东西?

感谢

+0

您使用Netbeans吗? – 2011-02-18 15:18:12

+0

@Stack是的,我是。但是我的JTree是自定义的。它不使用GUI编辑器。 – user489041 2011-02-18 15:19:54

回答

5

我不相信灵光支持JTree.lineStyle财产。只有MetalLookAndFeel可以。

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

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

4

原来你可以通过做

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

并不完美,但接近弄点这个效果。

0

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

以下代码段正在为我工​​作。

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 
}