Java Reference
In-Depth Information
Note The DefaultCellEditor class can also be used as a cell editor with the JTable component.
The JTable component is described in Chapter 18.
By default, the actual nodes of the JTree are implementations of the TreeNode interface or
its subinterface MutableTreeNode . The DefaultMutableTreeNode class is one such implementa-
tion that's commonly used, with the JTree.DynamicUtilTreeNode inner class helping to create
the tree nodes. The many tree nodes make up the TreeModel for the JTree , stored by default
into an instance of the DefaultTreeModel class.
Tree selection is managed by a TreeSelectionModel implementation, with a default imple-
mentation of DefaultTreeSelectionModel available. The JTree.EmptySelectionModel is also
available if you do not want the nodes of the tree to be selectable. The path of nodes from the
root of the tree to the selected node is maintained within a TreePath , with the help of a RowMapper
implementation to map rows to paths.
Note The tree-specific classes are found in the javax.swing.tree package. The event-related classes
are in the javax.swing.event package.
JTree Class
The JTree class forms the basis for visually displaying a set of hierarchical data elements.
Creating a JTree
There are seven different ways to create a JTree , with five different ways to specify the nodes:
public JTree()
JTree tree = new JTree();
public JTree(Hashtable value)
JTree tree = new JTree(System.getProperties());
public JTree(Object value[])
public static void main (String args[]) {
JTree tree = new JTree(args);
...
}
public JTree(Vector value)
Vector vector = new Vector();
vector.add("One");
vector.add("Two");
JTree tree = new JTree(vector);
 
Search WWH ::




Custom Search