Java JTree RemoveAll(JTree tree)

Here you can find the source of RemoveAll(JTree tree)

Description

Remove All

License

Open Source License

Declaration

public static void RemoveAll(JTree tree) 

Method Source Code

//package com.java2s;
/**/*w w w . ja v a2  s  .com*/
 * CEDP: Computer Evaluator for Dependability and Performance
 * This file is distributed under the University of Illinois Open Source
 * License. See LICENSE.TXT for details.
 */

import javax.swing.JTree;
import javax.swing.tree.DefaultMutableTreeNode;

public class Main {
    public static void RemoveAll(JTree tree) {
        // Tree root won't be removed.
        RemoveChildren((DefaultMutableTreeNode) tree.getModel().getRoot());
        tree.updateUI();
    }

    public static void RemoveChildren(DefaultMutableTreeNode node) {
        while (node.getChildCount() > 0) {
            RemoveChildren((DefaultMutableTreeNode) node.getFirstChild());
        }
        //System.out.println("" + node);
        node.removeFromParent();
    }
}

Related

  1. isPointOnTree(JTree tree, Point location)
  2. maxDepth(JTree tree, int depth)
  3. paint(JTree tree)
  4. pickFirstIfNone(JTree tree)
  5. printComponentTree(final JComponent fc)
  6. repaintSelection(JTree tree)
  7. restoreExpanstionState(JTree tree, int row, String expansionState)
  8. revalidateTree(java.awt.Component c)
  9. saveExpansionState(JTree tree)