TreeSelectionEvent: isAddedPath(int index) : TreeSelectionEvent « javax.swing.event « Java by API






TreeSelectionEvent: isAddedPath(int index)

  

import javax.swing.JTree;
import javax.swing.event.TreeSelectionEvent;
import javax.swing.event.TreeSelectionListener;
import javax.swing.tree.TreePath;

public class Main {
  public static void main(String[] argv) throws Exception {

    JTree tree = new JTree();

    tree.addTreeSelectionListener(new TreeSelectionListener() {
      public void valueChanged(TreeSelectionEvent evt) {
        TreePath[] paths = evt.getPaths();

        for (int i = 0; i < paths.length; i++) {
          if (evt.isAddedPath(i)) {
            System.out.println("This node has been selected");
          } else {
            System.out.println("This node has been deselected"); 
          }
        }
      }
    });
  }
}

   
    
  








Related examples in the same category

1.TreeSelectionEvent: getNewLeadSelectionPath()