e1022. Enabling and Disabling Multiple Selections in a JTree Component
// Create tree
JTree tree = new JTree();
// Allow only a single node to be selected (default)
tree.getSelectionModel().setSelectionMode(
TreeSelectionModel.SINGLE_TREE_SELECTION);
// Allow selection to span one vertical contiguous set of visible nodes
tree.getSelectionModel().setSelectionMode(
TreeSelectionModel.CONTIGUOUS_TREE_SELECTION);
// Allow multiple selections of visible nodes
tree.getSelectionModel().setSelectionMode(
TreeSelectionModel.DISCONTIGUOUS_TREE_SELECTION);
e1021.
Getting the Selected Nodes in a JTree Component
© 2002 Addison-Wesley.
|