JTree Line and Nimbus Style

I am using Nimbus. According to this link, you can achieve 3 different line styles using JTree:

enter image description here

Using the following code:

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

My JTree looks like this:

enter image description here

It has a No style, not a Horizontal style. Any idea why this could be? Does this have anything to do with Nmbus? Do I need to call something special after setting this property?

thanks

+6
java swing jtree nimbus
source share
3 answers

I do not believe that Nimbus supports the JTree.lineStyle property. Only 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.

+5
source share

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.

+4
source share

For those who are still interested in this:

The following snippet works 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
source share

All Articles