How can I find the parent of a leaf in a JTree?

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.


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.