本文整理汇总了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);
}