Getting a node in JTree

user489041 picture user489041 · Feb 25, 2011 · Viewed 16.2k times · Source

Simple question. I have a TreePath to a node in my JTree. How can I convert this TreePath to the DefaultMutableTreeNode the TreePath points too?

Answer

dontocsata picture dontocsata · Feb 25, 2011

You should be able to call getLastPathComponent on the TreePath and cast that for a TreeNode or DefaultMutableTreeNode and be good to go.

See: http://download.oracle.com/javase/6/docs/api/javax/swing/tree/TreePath.html#getLastPathComponent%28%29