expalin DefaultMutableTreeNode.getUserObject()

hello there,

Could you anyone tell me what this method does precisely.and when to use it.

DefaultMutableTreeNode.getUserObject()

cheers
zolf
zolfAsked:
Who is Participating?
 
objectsConnect With a Mentor Commented:
Say each node in the tree represent a Person and you want to find out the persons name

DefaultMutableTreeNode select = (DefaultMutableTreeNode)obj;
Person p = (Person) select.getUserObject();
String name = p.getName();
0
 
objectsCommented:
it returns the object that is associated with the tree node.
you use it whenever you need to access that object
0
 
zolfAuthor Commented:

Object obj = tree.getLastSelectedPathComponent();
DefaultMutableTreeNode select = (DefaultMutableTreeNode)obj;
System.out.println(select);

Object uObject = select.getUserObject();
System.out.println(uObject);

both the statements print the same.so what is the difference
0
 
objectsCommented:
you may want to access some property of the user object
0
 
zolfAuthor Commented:

for example ??
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.