aspose file tools*
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


Win a copy of Java 8 in Action this week in the Java 8 forum!
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 agree. Here's the link: http://aspose.com/file-tools
 
subject: DefaultMutableTreeNode and setParent
 
Similar Threads
Generics driving me crazy, for the fourth time
Object from Subclass to Superclass
JTree won't show expanded node
sorting jtree
sorting nodes in JTree