Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Adding a child to a node after previously removing all children?  RSS feed

 
Matt Wilcko
Ranch Hand
Posts: 65
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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!
 
Craig Wood
Ranch Hand
Posts: 1535
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Tell the JTree model. If you are using DefaultTreeModel it has some handy methods for this such as nodesWereRemoved.
 
Don't get me started about those stupid light bulbs.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!