Here you can find the source of makeTreePath(TreeNode treeNode)
public static TreePath makeTreePath(TreeNode treeNode)
//package com.java2s; /*//from w w w. j a v a 2 s. com * Copyright 2001 (C) MetaStuff, Ltd. All Rights Reserved. * * This software is open source. * See the bottom of this file for the licence. * * $Id: TreeNodeHelper.java,v 1.1.1.1 2001/05/22 08:12:55 jstrachan Exp $ */ import javax.swing.tree.TreeNode; import javax.swing.tree.TreePath; import java.util.LinkedList; public class Main { /** Creates a tree path from the root node of the tree to the specified treeNode instance */ public static TreePath makeTreePath(TreeNode treeNode) { LinkedList list = new LinkedList(); while (treeNode != null) { list.addFirst(treeNode); treeNode = treeNode.getParent(); } Object[] nodes = list.toArray(); return new TreePath(nodes); } }