How can I access userObject
in DefaultMutableTreeNode
How can I modify the user object or extract the values defined in it?
Asked
Active
Viewed 100 times
0
-
1how about reading its api doc? – kleopatra Oct 28 '12 at 16:33
-
1See also this [example](http://stackoverflow.com/a/11113648/230513). – trashgod Oct 28 '12 at 17:21
1 Answers
1
What about the methods setUserObject
and getUserObject
?

A.H.
- 63,967
- 15
- 92
- 126
-
my object contains an int p and char a and I add this to my structure DefaultMutableTreeNode node=new DefaultMutableTreeNode(this object); using get methods the object returned loses identity for p and a and I am not able to access or modify them. – Shark Oct 28 '12 at 19:09
-
@kamikaze: You can cast the outout of `getUserObject` to the required type since you know what type you have put into the node. After casting you can access your `p` and `a` again. The syntax if `MyType item = (MyType)node.getUserObject(); item.p....` – A.H. Oct 28 '12 at 19:14
-