• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

JTree traversal

 
Ben Wood
Ranch Hand
Posts: 342
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello,
I have a JTree, each node of which contains an object of my own invention called 'Effect'. I need to traverse this tree using the preorder method and access the data at each node as I go.
I have defined the below methods to handle the traversal and test the result by outputting something. This works fine, but the enumeration only holds the result of the Effect toString() method - so how can I use rootNode.preorderEnumeration, and then access the variables of the actual Effect data object stored in each node? Any ideas? Help is greatly appreciated
regards,
Ben.


 
ping203
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
try this
((DefaultMutableTreeNode)e.nextElement()).getUserObject()
since the return type of e.nextElement() is Object and you know it is a DefaultMutableTreeNode. Using the getUserObject() will return you a Effect-type object
 
Ben Wood
Ranch Hand
Posts: 342
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for the suggestion. That works. I also figured out that my root node, which I neither display nor use within the application, does not contain an Effect user object but contains a string user object - this was the 'root' cause of the problem ;-)
thanks for the help,
Ben.
[ January 14, 2002: Message edited by: Ben Wood ]
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic