Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

DefaultMutableTreeNode and setParent

 
Vladimir Bezugliy
Ranch Hand
Posts: 33
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


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
Posts: 1646
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
My guess: to avoid an infinate loop. insertNode() calls setParent(). If setParent() called insertNode(), chaos ensues.
 
Vladimir Bezugliy
Ranch Hand
Posts: 33
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
it is possible to add child to children directly.
Then there will not be a loop.
 
David Harkness
Ranch Hand
Posts: 1646
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic