Here you can find the source of searchForNodeV2(TreeNode node, String query, JTree tree, TreePath actualPath, boolean isRoot)
public static TreePath searchForNodeV2(TreeNode node, String query, JTree tree, TreePath actualPath, boolean isRoot)
//package com.java2s; /*/*from w w w.j av a 2s. c o m*/ * ACIDE - A Configurable IDE * Official web site: http://acide.sourceforge.net * * Copyright (C) 2007-2014 * Authors: * - Fernando S?enz P?rez (Team Director). * - Version from 0.1 to 0.6: * - Diego Cardiel Freire. * - Juan Jos? Ortiz S?nchez. * - Delf?n Rup?rez Ca?as. * - Version 0.7: * - Miguel Mart?n L?zaro. * - Version 0.8: * - Javier Salcedo G?mez. * - Version from 0.9 to 0.11: * - Pablo Guti?rrez Garc?a-Pardo. * - Elena Tejeiro P?rez de ?greda. * - Andr?s Vicente del Cura. * - Version from 0.12 to 0.16 * - Sem?ramis Guti?rrez Quintana * - Juan Jes?s Marqu?s Ortiz * - Fernando Ord?s Lorente * - Version 0.17 * - Sergio Dom?nguez Fuentes * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. */ import java.util.Enumeration; import javax.swing.JTree; import javax.swing.tree.TreeNode; import javax.swing.tree.TreePath; public class Main { public static TreePath searchForNodeV2(TreeNode node, String query, JTree tree, TreePath actualPath, boolean isRoot) { //Searches for the target node at the level if (node.toString().startsWith(query)) return actualPath.pathByAddingChild(node); if (node.isLeaf()) { return null; } Enumeration<TreeNode> e = (Enumeration<TreeNode>) node.children(); if (!e.hasMoreElements()) { TreePath tempPath = actualPath.pathByAddingChild(node); tree.setSelectionPath(tempPath); e = (Enumeration<TreeNode>) node.children(); } // Searches for the target node on the children of the node while (e.hasMoreElements()) { TreePath path = null; if (isRoot) path = searchForNodeV2(e.nextElement(), query, tree, actualPath, false); else path = searchForNodeV2(e.nextElement(), query, tree, actualPath.pathByAddingChild(node), false); if (path != null) { return path; } } return null; } }