This week's book giveaway is in the OCAJP 8 forum. We're giving away four copies of OCA Java SE 8 Programmer I Study Guide and have Edward Finegan & Robert Liguori on-line! See this thread for details.
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.
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
Joined: Aug 14, 2001
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 ]