I know how to create node with String as a name in the Tree. However I don't know how to associate object with tree. It will be great if u guys have some code as an example. Thank You very much.
I came across a similar problem a few days ago. The problem was, once you've set the user object of the node to your self defined objects how do you render it i.e is to say "How can I get the tree to get the name of the object it'll use as the String on the node from one of my objets methods ?". Here's how I was able to do it -
I subclassed JTree to override the convertValueToTextMethod. This method is called by the renderer code to get the String represented by the object at a node.
The object passed to the convertValueToText method is a MutableTreeNode object(I'm not sure yet) from which you can get your object by calling the getUserObject().
Now in your overridden method you have your user object from which you can get it's String representation(by calling one of your objects methods) & return this value.
And now your tree will show the Strings for objects the way you'd like them. HTH Ashish Hareet