本文整理汇总了Java中javax.swing.JTree.isRootVisible方法的典型用法代码示例。如果您正苦于以下问题:Java JTree.isRootVisible方法的具体用法?Java JTree.isRootVisible怎么用?Java JTree.isRootVisible使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类javax.swing.JTree
的用法示例。
在下文中一共展示了JTree.isRootVisible方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getTextForNode
import javax.swing.JTree; //导入方法依赖的package包/类
private String getTextForNode(JTree tree, int row) {
TreePath treePath = tree.getPathForRow(row);
if (treePath == null) {
return row + "";
}
StringBuilder sb = new StringBuilder();
int start = tree.isRootVisible() ? 0 : 1;
Object[] objs = treePath.getPath();
for (int i = start; i < objs.length; i++) {
String pathString;
if (objs[i].toString() == null) {
pathString = "";
} else {
pathString = escapeSpecialCharacters(getTextForNodeObject(tree, objs[i]));
}
sb.append("/" + pathString);
}
return sb.toString();
}
示例2: getPath
import javax.swing.JTree; //导入方法依赖的package包/类
private TreePath getPath(JTree tree, String path) {
String[] tokens = path.substring(1).split("(?<!\\\\)/");
TreeModel treeModel = tree.getModel();
if (treeModel == null) {
throw new RuntimeException("Could not find model for tree");
}
Object rootNode = treeModel.getRoot();
int start = tree.isRootVisible() ? 1 : 0;
TreePath treePath = new TreePath(rootNode);
StringBuilder searchedPath = new StringBuilder();
if (tree.isRootVisible()) {
String rootNodeText = unescapeSpecialCharacters(tokens[0]);
searchedPath.append("/" + rootNodeText);
assertTrue("JTree does not have a root node!", rootNode != null);
assertTrue("JTree root node does not match: Expected </" + getPathText(tree, treePath) + "> Actual: <"
+ searchedPath.toString() + ">", searchedPath.toString().equals("/" + getPathText(tree, treePath)));
}
for (int i = start; i < tokens.length; i++) {
String childText = unescapeSpecialCharacters(tokens[i]);
searchedPath.append("/" + childText);
boolean matched = false;
tree.expandPath(treePath);
for (int j = 0; j < treeModel.getChildCount(treePath.getLastPathComponent()); j++) {
Object child = treeModel.getChild(treePath.getLastPathComponent(), j);
TreePath childPath = treePath.pathByAddingChild(child);
if (childText.equals(getPathText(tree, childPath))) {
treePath = childPath;
matched = true;
break;
}
}
if (!matched) {
return null;
}
}
return treePath;
}
示例3: closeAllPaths
import javax.swing.JTree; //导入方法依赖的package包/类
public void closeAllPaths(JTree tree) {
TreePath pathToRoot = new TreePath(tree.getModel().getRoot());
closePaths(tree, pathToRoot);
if (!tree.isRootVisible())
tree.expandPath(pathToRoot);
}
示例4: closeAllPaths
import javax.swing.JTree; //导入方法依赖的package包/类
public static void closeAllPaths(JTree tree) {
TreePath pathToRoot = new TreePath(tree.getModel().getRoot());
closePaths(tree, pathToRoot);
if (!tree.isRootVisible())
tree.expandPath(pathToRoot);
}