Here you can find the source of getPath(TreeNode treeNode)
TreeNode
get the corresponding TreePath
Parameter | Description |
---|---|
treeNode | a parameter |
public static TreePath getPath(TreeNode treeNode)
//package com.java2s; //License from project: BSD License import java.util.ArrayList; import java.util.List; import javax.swing.tree.TreeNode; import javax.swing.tree.TreePath; public class Main { /**//from w w w . jav a2 s . com * Given a <code>TreeNode</code> get the corresponding <code>TreePath</code> * @param treeNode * @return */ public static TreePath getPath(TreeNode treeNode) { List<Object> nodes = new ArrayList<Object>(); if (treeNode != null) { nodes.add(treeNode); treeNode = treeNode.getParent(); while (treeNode != null) { nodes.add(0, treeNode); treeNode = treeNode.getParent(); } } return nodes.isEmpty() ? null : new TreePath(nodes.toArray()); } }