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
How to print nodes of a Binary tree?
What is a Presistent Object?
What is a method in programming?
Is integer passed by reference in java?
Which collections are thread safe in java?
What is the SimpleTimeZone class?
What is variable and example?
What is the difference between public, private, protected, and friend access?
Is void a type?
How can you handle java exceptions?
What is the core java?
Why are functions called methods in java?
Is char a data type in java?
what is a green thread? : Java thread
I want to control database connections in my program and want that only one thread should be able to make database connection at a time. How can I implement this logic?