开发者

JTree Line Style and Nimbus

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:

JTree Line Style and Nimbus

While using the following code:


theTree.putClientProperty("JTree.lineStyle", "Horizontal"开发者_如何学C);

My JTree looks like this:

JTree Line Style and Nimbus

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


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.


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.


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
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜