This week's book giveaway is in the Kotlin forum.
We're giving away four copies of Kotlin in Action and have Dmitry Jemerov & Svetlana Isakova on-line!
See this thread for details.
Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

How to retrieve an object stored in a tree.DefaultMutableTreeNode?  RSS feed

 
Bruce Jin
Ranch Hand
Posts: 672
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I store a object (for example, a new Boolean(true)) in DefaultMutableTreeNode.
How can I get it back?
The following code generates a ClassCastException because tree.getLastSelectedPathComponent() returns a DefaultMutableTreeNode object. What to do?
public void valueChanged(TreeSelectionEvent event) {

Boolean b = (Boolean) tree.getLastSelectedPathComponent();
}
 
Josh Rehman
Ranch Hand
Posts: 63
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Have you read the javadocs? Did you look at how you are storing the object, and look for the symmetrical method? If you used setUserObject(Object), guess what? There is a getUserObject() method as well! Shocking!
 
Consider Paul's rocket mass heater.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!