JTree를 처음 사용하기 때문에 몇 가지 기본적인 것들을 간과한다면 저와 함께하시기 바랍니다. Jtree 파일 탐색기에서 작업하고 있습니다. 그것은 디렉토리를 취하고, 노드를 추가하고, 노드와 그 모든 좋은 것들을 선택합니다. 기본 사항이 완료되었습니다. 추가 구현은 선택된 노드의 파일/폴더 크기를 제공하는 것을 포함하는데 이는 매우 간단합니다. 그러나 문제는 트리를 검색하려고하는 것입니다. 파일이 있음을 인식합니다. 그러나 재귀는 어떤 이유로 스스로를 반복하고 있습니까 ??? 그리고 그 가치는 제대로 돌아 오지 않습니다. 참조 용으로 두 가지 방법을 포함했습니다. 이것에 관련된 독서가있는 경우에, 또한 중대하게 평가 될 것이다.JTree Search 재발생 관련 문제
public void searchTree(String find)
{
TreePath root = tree.getPathForRow(0);
System.out.println(search (root, find));
}
public String search (TreePath path, String find)
{
TreeNode currentNode = (TreeNode)path.getLastPathComponent();
String findPath = null;
if (currentNode.isLeaf() && currentNode.toString().startsWith(find))
{
findPath = path.getPath()[path.getPath().length-2].toString() + File.separator + path.getPath()[path.getPath().length-1].toString();
return findPath;
}
if (!currentNode.isLeaf() && currentNode.getChildCount()> 0)
for (int i = 0; i < currentNode.getChildCount(); i++)
search(path.pathByAddingChild(currentNode.getChildAt(i)), find);
return findPath;
}
정확하게 말하면 검색 결과는 두 번 나타납니다. 내가 도대체 뭘 잘못하고있는 겁니까???