Preventing the Expansion or Collapse of a Node in a JTree Component - Java Swing

Java examples for Swing:JTree

Description

Preventing the Expansion or Collapse of a Node in a JTree Component

Demo Code

import javax.swing.JTree;
import javax.swing.tree.TreePath;

public class Main {
  public void main(String[] argv) {
    JTree tree = new JTree() {
      protected void setExpandedState(TreePath path, boolean state) {
        // Ignore all collapse requests; collapse events will not be fired
        if (state) {
          super.setExpandedState(path, state);
        }/*  ww  w  .ja v  a2s  .  c  o  m*/
      }
    };
  }
}

Related Tutorials