This week's book giveaway is in the OO, Patterns, UML and Refactoring forum.
We're giving away four copies of Refactoring for Software Design Smells: Managing Technical Debt and have Girish Suryanarayana, Ganesh Samarthyam & Tushar Sharma on-line!
See this thread for details.
The moose likes Beginning Java and the fly likes DefaultMutableTreeNode and setParent Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Java » Beginning Java
Bookmark "DefaultMutableTreeNode and setParent" Watch "DefaultMutableTreeNode and setParent" New topic
Author

DefaultMutableTreeNode and setParent

Vladimir Bezugliy
Ranch Hand

Joined: Sep 29, 2004
Posts: 33


Why method setParent only set parent for node.
But method insert() inserts child node and set parent for this child node.
Why method setParent do not add node to the children?
David Harkness
Ranch Hand

Joined: Aug 07, 2003
Posts: 1646
My guess: to avoid an infinate loop. insertNode() calls setParent(). If setParent() called insertNode(), chaos ensues.
Vladimir Bezugliy
Ranch Hand

Joined: Sep 29, 2004
Posts: 33
it is possible to add child to children directly.
Then there will not be a loop.
David Harkness
Ranch Hand

Joined: Aug 07, 2003
Posts: 1646
True, but then it has to pick where to insert it (top or bottom). But that just seems like a bug waiting to happen. The bottom line seems to be that you shouldn't call setParent() yourself; problem solved.
 
I’ve looked at a lot of different solutions, and in my humble opinion Aspose is the way to go. Here’s the link: http://aspose.com
 
subject: DefaultMutableTreeNode and setParent
 
jQuery in Action, 3rd edition