[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.
Farmers know to never drive a tractor near a honey locust tree. But a tiny ad is okay:
Rocket Oven Kickstarter - from the trailboss
https://coderanch.com/t/695773/Rocket-Oven-Kickstarter-trailboss


This thread has been viewed 559 times.

All times above are in ranch (not your local) time.
The current ranch time is
Jul 22, 2018 21:49:02.