Here you can find the source of pathByAddingChildAsStr(TreePath currPath, String child)
public static TreePath pathByAddingChildAsStr(TreePath currPath, String child)
//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; } }