Java JTree Path pathByAddingChildAsStr(TreePath currPath, String child)

Here you can find the source of pathByAddingChildAsStr(TreePath currPath, String child)

Description

path By Adding Child As Str

License

Open Source License

Declaration

public static TreePath pathByAddingChildAsStr(TreePath currPath, String child) 

Method Source Code


//package com.java2s;
//License from project: Open Source License 

import javax.swing.tree.DefaultMutableTreeNode;

import javax.swing.tree.TreePath;

public class Main {
    public static TreePath pathByAddingChildAsStr(TreePath currPath, String child) {
        // returns TreePath to child given by String, if child doesn't exist returns null!
        DefaultMutableTreeNode currNode = (DefaultMutableTreeNode) currPath.getLastPathComponent();
        for (int i = 0; i < currNode.getChildCount(); i++) {
            if (((DefaultMutableTreeNode) currNode.getChildAt(i)).getUserObject().toString().equals(child)) {
                return new TreePath(((DefaultMutableTreeNode) currNode.getChildAt(i)).getPath());
            }/*  ww w.  j a v  a  2 s . c  om*/
        }
        return null;
    }
}

Related

  1. isTreePathContainedInExpansionState(TreePath treePath, ArrayList expansionStateStrings)
  2. lastPathComponents(TreePath[] paths)
  3. loadExpansionState(JTree tree, Enumeration expansionState)
  4. makeLocalFilePath(TreePath treePath)
  5. makeTreePath(TreeNode treeNode)
  6. pathContains(TreePath[] paths, Class clazz)
  7. pathToDepth(TreePath path, int depth)
  8. resourceFromTreePath(TreePath path)
  9. restoreSelectionPath(JTree parentTree)