本文整理匯總了Java中javafx.scene.control.TreeView.isShowRoot方法的典型用法代碼示例。如果您正苦於以下問題:Java TreeView.isShowRoot方法的具體用法?Java TreeView.isShowRoot怎麽用?Java TreeView.isShowRoot使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類javafx.scene.control.TreeView
的用法示例。
在下文中一共展示了TreeView.isShowRoot方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: getTextForNode
import javafx.scene.control.TreeView; //導入方法依賴的package包/類
public String getTextForNode(TreeView<?> treeView, TreeItem<?> selectedItem) {
StringBuilder sb = new StringBuilder();
Object[] treePath = buildTreePath(selectedItem);
int start = treeView.isShowRoot() ? 0 : 1;
for (int i = start; i < treePath.length; i++) {
String pathString = escapeSpecialCharacters(getTextForNodeObject((TreeItem<?>) treePath[i]));
sb.append("/").append(pathString);
}
return sb.toString();
}
示例2: getPath
import javafx.scene.control.TreeView; //導入方法依賴的package包/類
public TreeItem<?> getPath(TreeView<?> treeView, String path) {
String[] tokens = path.substring(1).split("(?<!\\\\)/");
Object rootNode = treeView.getRoot();
int start = treeView.isShowRoot() ? 1 : 0;
List<TreeItem<?>> treePath = new ArrayList<TreeItem<?>>();
treePath.add((TreeItem<?>) rootNode);
StringBuilder searchedPath = new StringBuilder();
if (treeView.isShowRoot()) {
String rootNodeText = unescapeSpecialCharacters(tokens[0]);
searchedPath.append("/" + rootNodeText);
if (rootNode == null) {
throw new RuntimeException("TreeView does not have a root node!");
}
if (!searchedPath.toString().equals("/" + getPathText(treePath))) {
throw new RuntimeException("TreeView root node does not match: Expected </" + getPathText(treePath) + "> Actual: <"
+ searchedPath.toString() + ">");
}
}
for (int i = start; i < tokens.length; i++) {
String childText = unescapeSpecialCharacters(tokens[i]);
searchedPath.append("/" + childText);
boolean matched = false;
TreeItem<?> item = treePath.get(treePath.size() - 1);
item.setExpanded(true);
for (int j = 0; j < item.getChildren().size(); j++) {
Object child = item.getChildren().get(j);
treePath.add((TreeItem<?>) child);
List<TreeItem<?>> childPath = treePath;
if (childText.equals(getPathText(childPath))) {
treePath = childPath;
matched = true;
break;
}
}
if (!matched) {
return null;
}
}
return treePath.get(treePath.size() - 1);
}