Results 1 to 5 of 5
- 06-27-2011, 07:45 PM #1
Member
- Join Date
- Jul 2010
- Location
- Lima, Peru
- Posts
- 47
- Rep Power
- 0
Get child of DefaultMutableTreeNode
Hello.
I have a DefaultMutableTreeNode.
This DMTN has several children.
I want to do something like this:
Simple enough. However, apparently the method getChildAt(int) returns an object of type TreeNode rather than DefaultMutableTreeNode.Java Code:for(int i = 0; i< dmt.getChildCount(); i++){ [INDENT]System.out.println(dmt.getChildAt(i).getUserObject().toString());[/INDENT] }
TreeNodes don't have a getUserObject() method.
ALSO, I am not allowed to cast a TreeNode to a DefaultMutableTreeNode.
Seriously java? Why can't I get the child of a DefaultMutableTreeNode as a DefaultMutableTreeNode.
Please let me know if there is a method of doing what I want to do (iterate through the children of my dmtn and do something with their userObject).
- 06-27-2011, 07:51 PM #2
- Join Date
- Sep 2008
- Location
- Voorschoten, the Netherlands
- Posts
- 11,427
- Blog Entries
- 7
- Rep Power
- 17
When people rob a bank they get a penalty; when banks rob people they get a bonus.
- 06-27-2011, 08:03 PM #3
Member
- Join Date
- Jul 2010
- Location
- Lima, Peru
- Posts
- 47
- Rep Power
- 0
Okay, I think my tree is not made of DefaultMutableTreeNodes.
I generated my tree from vectors, which ultimately use a custom-made object as values.
I wanted to work with this custom made object that I generated the tree from.
How do I work with the objects of the tree, given the fact that I generated it from vectors?
OR is there no way to retrieve the values from the tree once I have generated it from vectors?
- 06-27-2011, 08:22 PM #4
- Join Date
- Sep 2008
- Location
- Voorschoten, the Netherlands
- Posts
- 11,427
- Blog Entries
- 7
- Rep Power
- 17
- 06-27-2011, 10:53 PM #5
Member
- Join Date
- Jul 2010
- Location
- Lima, Peru
- Posts
- 47
- Rep Power
- 0
Similar Threads
-
DefaultMutableTreeNode
By vendetta in forum New To JavaReplies: 0Last Post: 03-02-2010, 04:15 PM -
How to add different menuitems to child node
By sudhakar.cheru in forum AWT / SwingReplies: 2Last Post: 09-16-2009, 06:32 AM -
How to get value of specific child node
By sito42 in forum New To JavaReplies: 1Last Post: 07-13-2009, 12:00 PM -
Cannot add or update a child row....
By Pierced1 in forum JDBCReplies: 2Last Post: 06-29-2009, 02:32 AM -
Child Labor
By freddieMaize in forum Forum LobbyReplies: 1Last Post: 11-16-2008, 08:59 PM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks