Java Utililty Methods JTree Path

List of utility methods to do JTree Path

Description

The list of methods to do JTree Path are organized into topic(s).

Method

Object[]getObjectPathForNode(final TreeNode node)
get Object Path For Node
final LinkedList<TreeNode> list = new LinkedList<TreeNode>();
TreeNode runner = node;
while (runner != null) {
    list.add(0, runner);
    runner = runner.getParent();
return list.toArray(new TreeNode[list.size()]);
TreePathgetPath(TreeNode node)
get Path
List list = new ArrayList();
while (node != null) {
    list.add(node);
    node = node.getParent();
Collections.reverse(list);
return new TreePath(list.toArray());
TreePathgetPath(TreeNode treeNode)
get Path
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());
TreePathgetPath(TreeNode treeNode)
Given a TreeNode get the corresponding TreePath
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());
TreePathgetPath(TreeNode treeNode)
get Path
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());
TreePathgetPath(TreeNode treeNode)
get Path
List<TreeNode> nodes = new ArrayList<TreeNode>();
while (treeNode != null) {
    nodes.add(0, treeNode);
    treeNode = treeNode.getParent();
return nodes.isEmpty() ? null : new TreePath(nodes.toArray());
StringgetPathStr(TreeNode[] projectNodes)
creates String path from treeNodes
String str = new String();
for (int counter = 0; counter < projectNodes.length; counter++) {
    if (counter == projectNodes.length - 1) {
        str = str + projectNodes[counter];
        continue;
    str = str + projectNodes[counter] + SEPERATOR;
return str;
TreeNodegetTree(List paths)
constract tree from list of paths.
return getTree(paths, null);
TreePathgetTreePath(TreeNode treeNode)
get Tree Path
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());
TreePathgetTreePath(TreeNode treeNode)
gets path from the current node to high up in the Tree in TreePath format
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());