[Logo]
Forums Register Login
Adding a child to a node after previously removing all children?
Hi,
I remove node's chidren by calling removeAllChidren(). This seems to work fine. However, if I try to add a child after doing thing, all of the previously removed children come back? My code snippet is below:

//remove node's children
node.removeAllChildren();
//add a Child
DefaultMutableTreeNode junk = new DefaultMutableTreeNode("junk");
node.add(junk);

How do I add a new child to a node but not have the removed children come back at the same time? Are these values stored in an array that i have to edit?

Thanks!
Tell the JTree model. If you are using DefaultTreeModel it has some handy methods for this such as nodesWereRemoved.
WHAT is your favorite color? Blue, no yellow, ahhhhhhh! Tiny ad:
Thread Boost - a very different sort of advertising
https://coderanch.com/t/674455/Thread-Boost-feature


This thread has been viewed 546 times.

All times above are in ranch (not your local) time.
The current ranch time is
Apr 24, 2018 17:13:21.