Allow multiple selections of visible nodes : JTree Selection « Swing « Java Tutorial

import javax.swing.JFrame;
import javax.swing.JScrollPane;
import javax.swing.JTree;
import javax.swing.tree.TreeSelectionModel;

public class TreeDISCONTIGUOUSSelection {
  public static void main(String[] argv) {
    JTree tree = new JTree();


    JFrame frame = new JFrame("tree DISCONTIGUOUS selection");
    frame.add(new JScrollPane(tree));
    frame.setSize(380, 320);


14.71.JTree Selection
14.71.1.Enabling and Disabling Multiple Selections in a JTree Component
14.71.2.Allow only a single node to be selected (default)Allow only a single node to be selected (default)
14.71.3.Allow selection to span one vertical contiguous set of visible nodes
14.71.4.Allow multiple selections of visible nodes
14.71.5.Listening for Selection Events in a JTree Component
14.71.6.Getting the Selected Nodes in a JTree Component
14.71.7.Returns a TreePath containing the specified node.
14.71.8.Determine if the third item is selected