0

How can I access userObject in DefaultMutableTreeNode How can I modify the user object or extract the values defined in it?

trashgod
  • 200,320
  • 28
  • 229
  • 974
Shark
  • 11
  • 2

1 Answers1

1

What about the methods setUserObject and getUserObject?

A.H.
  • 61,009
  • 14
  • 85
  • 115
  • 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
  • thnx A.H. that was very naive – Shark Oct 28 '12 at 19:26