Simple question. I have a TreePath for a node in my JTree. How can I convert this TreePath to DefaultMutableTreeNode into TreePath points?
You must be able to call getLastPathComponentin TreePathand drop it for TreeNodeor DefaultMutableTreeNodeand be good to go.
getLastPathComponent
TreePath
TreeNode
DefaultMutableTreeNode
See: http://download.oracle.com/javase/6/docs/api/javax/swing/tree/TreePath.html#getLastPathComponent%28%29
If your treemodel consists of DefaultMutableTreeNodes, you can simply use node=(DefaultMutableTreeNode)path.getLastPathComponent();
node=(DefaultMutableTreeNode)path.getLastPathComponent();
- DefaultTreeModel
private TreePath getTreePath(TreeNode node) { TreeNode[] nodes = model.getPathToRoot(node); TreePath path = new TreePath(nodes); return path; }