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 are the topics in advance java?
What are java packages? What's the significance of packages?
What are streams in java 8?
What is JFC?
What is bool mean?
What are the 7 types of characters?
Can private class be inherited in java?
How do you identify if jvm is 32-bit or 64-bit from java program?
Is it necessary that each try block must be followed by a catch block?
how to split string in java?
What’s the difference between constructors and other methods?
Hi friends am new to java. I read jar file means collection of java files. For executing struts application what are the necessary jar files. " struts.jar " file contains what. can u explain
What is serialization in java?
How to compare strings in java?
Explain why wait(), notify() and notifyall() methods are in object class rather than in the reading class?