import java.util.ArrayList; import java.util.Collections; import java.util.List; import javax.swing.tree.TreeNode; import javax.swing.tree.TreePath; public class Main { public TreePath getPath(TreeNode node) { List<TreeNode> list = new ArrayList<TreeNode>(); while (node != null) { list.add(node); node = node.getParent(); } Collections.reverse(list); return new TreePath(list.toArray()); } }