Here you can find the source of searchUnexpandedPath(JTree tree, TreePath path, int index, TreeNode node, TreePath[] result, boolean compareOnlyLabels)
public static boolean searchUnexpandedPath(JTree tree, TreePath path, int index, TreeNode node, TreePath[] result, boolean compareOnlyLabels)
//package com.java2s; /* TouchStone design platform is a software to design protocols for lab * * experiments. It is published under the terms of a BSD license * * (see details below) * * Author: Caroline Appert (appert@lri.fr) * * Copyright (c) 2010 Caroline Appert and INRIA, France. * * TouchStone design platform reuses parts of an early version which were * * programmed by Matthis Gilbert. * *********************************************************************************/ import java.util.Enumeration; import javax.swing.JTree; import javax.swing.tree.TreeNode; import javax.swing.tree.TreePath; public class Main { public static boolean searchUnexpandedPath(JTree tree, TreePath path, int index, TreeNode node, TreePath[] result, boolean compareOnlyLabels) { Object[] pathElements = path.getPath(); if (index >= pathElements.length) { return !tree.isExpanded(result[0]); }/*w ww .jav a 2 s . c o m*/ Object elementToSearch = pathElements[index]; Enumeration<?> enumeration = node.children(); while (enumeration.hasMoreElements()) { TreeNode next = (TreeNode) enumeration.nextElement(); if ((compareOnlyLabels && next.toString().compareTo(elementToSearch.toString()) == 0) || (!compareOnlyLabels && next.equals(elementToSearch))) { TreePath[] potentialResult = new TreePath[1]; potentialResult[0] = result[0].pathByAddingChild(next); if (searchUnexpandedPath(tree, path, index + 1, next, potentialResult, compareOnlyLabels)) { result[0] = potentialResult[0]; return true; } } } return false; } }