JTree Line Style and Nimbus

4.1k views Asked by At

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:

enter image description here

While using the following code:


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

My JTree looks like this:

enter image description here

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

3

There are 3 answers

0
Angel Velazquez On

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
}
4
dogbane On

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.

0
user1359010 On

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.