I have recently been attempting to convert a system to a unified look and feel (In this case Nimbus). However certain components require alteration from the defaults and I don't want to just change the defaults because of a single component.
I am trying to override the row highlight colour for a JTree component. I have managed to switch it off entirely but this is not what I am after.
From reading the various questions on here I have tried using:
UIDefaults overrides = new UIDefaults();
overrides.put("Tree.selectionBackground", new Color(200,200,200));
overrides.put("nimbusSelectionBackground", new Color(200,200,200));
modelTree = new ModelTree(treeModel);
modelTree.putClientProperty("Nimbus.Overrides", overrides);
modelTree.putClientProperty("Nimbus.Overrides.InheritDefaults",true);
Where modelTree extends the standard JTree. Without these overrides the look is entirely default and I know that there is nothing overriding these properties in the derrived class.
The problem is that the properties are being ignored, the colour stays the same as default while InheritDefaults is true and the row highlight is switched off when it is false.
What I am after is a simple recolouring of the row highlight.
Thanks in advance
EDIT:
public static class treeTest extends JPanel {
public treeTest() {
super();
try {
UIManager.setLookAndFeel(NimbusLookAndFeel.class.getName());
} catch (Exception e) {
e.printStackTrace();
}
//UIManager.put("Tree.selectionForeground", Color.BLACK);
UIDefaults overrides = new UIDefaults();
overrides.put("Tree.selectionForeground", Color.BLACK);
JTree defaultsTree = new JTree();
JTree overiddenTree = new JTree();
overiddenTree.putClientProperty("Nimbus.Overrides", overrides);
overiddenTree.putClientProperty("Nimbus.Overrides.InheritDefaults", false);
add(defaultsTree);
add(overiddenTree);
}
}
I hope this is an acceptable SSCCE (It's the first time I've made one). Should override the default text colour on the selected line for the overiddenTree component but doesn't.
Uncommenting the line that overwrites the default to do the same does work but will set for all instances.