TreeItem<String> searchTreeItem(TreeItem<String> item, String name) {
if(item.getValue().equals(name)) return item; // hit!
// continue on the children:
TreeItem<String> result = null;
for(TreeItem<String> child : item.getChildren()){
result = searchTreeItem(child, name);
if(result != null) return result; // hit!
}
//no hit:
return null;
}
If you want to search the whole tree treeView for a node with name "bigdev", just pass in the root:
TreeItem<String> result = searchTreeItem(treeView.getRoot(), "bigdev");
great
ReplyDeleteGreat! We will be connecting to this enormous post on our site. Continue the good writing.
ReplyDelete