Answer Posted / yuvaraaj
You have a couple of choices:
Update the model directly:
DefaultTreeModel model = (DefaultTreeModel) tree.getModel();
DefaultMutableTreeNode root = (DefaultMutableTreeNode) model.getRoot();
model.insertNodeInto(new DefaultMutableTreeNode("another_child"), root, root.getChildCount());
Update the tree nodes and then notify the model:
DefaultTreeModel model = (DefaultTreeModel)tree.getModel();
DefaultMutableTreeNode root = (DefaultMutableTreeNode)model.getRoot();
root.add(new DefaultMutableTreeNode("another_child"));
model.reload(root);
The same applies for removing nodes.
The DefaultTreeModel has a removeNodeFromParent(...) which will update the model directly.
Or you can use the remove(...) method of the DefaultMutableTreeNode class. In which case you would need to do the reload().
| Is This Answer Correct ? | 0 Yes | 0 No |
Post New Answer View All Answers
What is a function easy definition?
What is the base class of all exception classes?
What is the use of volatile in java?
How do you get length in java?
How do you remove duplicates in java?
What is gui programming?
Why do we need wrapper classes?
What is the advantage of functional interface in java 8?
Can we create object of static class?
What are predefined functions?
What is substring in java?
Does isempty check for null?
Is a copy constructor?
What happens if an exception is throws from an object's constructor?
What is the relationship difference the canvas class and the graphics class?