Java Reference
In-Depth Information
fixedRowHeight property. Changing the value of rowHeight to a value such as 12 pixels results in
the fixedRowHeight property having a setting of true .
The largeModel property setting is a suggestion to the TreeUI to help it display the tree.
Initially, this setting is false because a tree has many data elements and you don't want the
user interface component to cache excessive information (such as node renderer sizes) about
the tree. For smaller models, caching information about a tree doesn't require as much memory.
The current setting of lastSelectedPathComponent property is the contents of the last selected
node. At any time, you can ask a tree what is selected. If nothing is selected, this property's
value will be null . Because trees support multiple selections, the lastSelectedPathComponent
property doesn't necessarily return all selected nodes. You can also modify the selection path
with the anchorSelectionPath and leadSelectionPath properties.
The three selection row properties— leadSelectionRow , minSelectionRow , and
maxSelectionRow —are interesting in that the row values can change based on another parent
node's opening or closing. When a single node in the tree is selected, all three properties have
the same setting. You can get an array of all selected row indices with the selectionRows property.
However, there is no way to map a row number to a node in the tree. Instead, use the
selectionPaths property, which provides an array of TreePath elements. As you'll soon see,
each TreePath includes the selected node and all nodes on the path from the root node to the
selected node.
There are three visibility-related settings of a tree. You can adjust the preferred number of
rows to display for the tree by setting the visibleRowCount property. By default, the setting is 20.
This setting is valid only when a particular tree is within a JScrollPane or some other component
that uses the Scrollable interface. The second visibility-related setting has to do with whether
the root node is visible. When the tree is created from a Hashtable , array, or Vector constructor, the
root isn't visible. Otherwise, it will be visible initially. Changing the rootVisible property allows
you to alter this setting. The other visibility-related setting has to do with the icon next to the root
node. By default, there is no icon at the root level to show the open or closed state of the root of
the tree. All nonroot nodes always have this type of icon. To show the root icon, set the
showsRootHandles property to true .
Three additional selection-oriented properties are also available. The toggleClickCount
property allows you to control how many clicks over a parent node will trigger selection or
expansion of the node. The default setting is 2. The scrollsOnExpand property causes the tree to
scroll when a node is expanded such that as many descendants as possible will be visible. By
default, this is true . The third property, expandsSelectedPath , is true by default, causing the
selected path for a node to be expanded when programmatically selected. If, however, you
don't wish to expand the tree upon programmatic selection, you can set this to false and leave
the path hidden.
Customizing a JTree Look and Feel
Each installable Swing look and feel provides a different JTree appearance and set of default
UIResource values. Figure 17-4 shows the appearance of the JTree container for the preinstalled
set of look and feel types: Motif, Windows, and Ocean.
Search WWH ::




Custom Search