Removing a Node to a JTree Component

// Create tree JTree tree = new JTree(); DefaultTreeModel model = (DefaultTreeModel)tree.getModel(); // Find node to remove int startRow = 0; String prefix = "b"; TreePath path = tree.getNextMatch(prefix, startRow, Position.Bias.Forward); MutableTreeNode node = (MutableTreeNode)path.getLastPathComponent(); // Remove node; if node has descendants, all descendants are removed as well model.removeNodeFromParent(node); // The root cannot be removed with removeNodeFromParent(); // use the following to remove the root model.setRoot(null);

Comments

23 Feb 2010 - 11:11pm by Anonymous (not verified)

not good

Post a comment

More information about formatting options

CAPTCHA
This question is for testing whether you are a human visitor and to prevent automated spam submissions.
Image CAPTCHA
Enter the characters shown in the image. Ignore spaces and be careful about upper and lower case.