The Java Developers Almanac 1.4


Order this book from Amazon.

   
Home > List of Packages > javax.swing.tree  [15 examples] > Selections  [2 examples]

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);

 Related Examples
e1021. Getting the Selected Nodes in a JTree Component

See also: Events    Layout    Node Expansion    Nodes   


© 2002 Addison-Wesley.