Java Reference
In-Depth Information
Of the many different JTree resources, five are for the various icons displayed within the
JTree . To see how the five icons are positioned, examine Figure 17-5. If you just want to change
the icons (and possibly the colors) of a tree, all you need to do is change the icon properties
with lines such as the following:
UIManager.put("Tree.openIcon", new DiamondIcon(Color.RED, false));
Figure 17-5. JTree icons
The purpose of the Tree.hash color property may not be immediately obvious. This color
is for the lines drawn to connect nodes. With the Metal look and feel, and Ocean theme, by
default, angled lines connect the nodes. To enable the drawing of these lines, you must set the
JTree.lineStyle client property. This property isn't a UIResource property, but rather a client
property set with the public final void putClientProperty(Object key, Object value) method
of JComponent . The JTree.lineStyle property has the following valid settings:
None , for not drawing lines to connect nodes
Angled , the default setting for Ocean, for drawing lines in the Tree.hash color to connect
the nodes
Horizontal , for drawing horizontal lines between first-level nodes in the Tree.line color
Note The JTree.lineStyle client property is used only by the Metal look and feel. If the current look and
feel isn't Metal or one of its themes like Ocean, the property setting will be ignored if set (unless a custom look
and feel takes advantage of the setting). The other system-provided look and feel classes don't use this setting.
With client properties, you first must create the tree and then set the property. This client
property is specific to tree components, and it is not set for all trees. Therefore, creating a tree
with no lines entails using the following lines of code:
JTree tree = new JTree();
tree.putClientProperty("JTree.lineStyle", "None");
Figure 17-6 shows the results.
 
Search WWH ::




Custom Search