How can I find the parent of a leaf in a JTree?
Created May 4, 2012
Sandip Chitale The nodes of a JTree implement the
javax.swing.tree.TreeNode interafce. There is
a method to the parent in that interface i.e.
javax.swing.TreeNode.getParent();
javax.swing.TreeNode.getParent();
Details are here - http://java.sun.com/products/jdk/1.2/docs/api/javax/swing/tree/TreeNode.html
[FAQ Manager Note] This only applies when you're using a TreeModel that uses TreeNodes. This is the case of the default TreeModel used by JTree. If you define or use a custom TreeModel that doesn't use TreeNodes as its nodes, you will need to supply another method to find the parent node.