本文整理汇总了Java中javax.swing.JTree.expandPath方法的典型用法代码示例。如果您正苦于以下问题:Java JTree.expandPath方法的具体用法?Java JTree.expandPath怎么用?Java JTree.expandPath使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类javax.swing.JTree
的用法示例。
在下文中一共展示了JTree.expandPath方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: restoreExpansionState
import javax.swing.JTree; //导入方法依赖的package包/类
/**
* Expands all repositories and nodes, which have been saved before. Restores selected paths,
* which have been saved proviously.
*
* @param tree
* The related tree, containing the path(s)
*/
public void restoreExpansionState(JTree tree) {
for (int i = 0; i < tree.getRowCount(); i++) {
TreePath path = tree.getPathForRow(i);
Object entryObject = path.getLastPathComponent();
if (entryObject instanceof Entry) {
Entry entry = (Entry) entryObject;
String absoluteLocation = entry.getLocation().getAbsoluteLocation();
if (expandedRepositories.contains(absoluteLocation) || expandedNodes.contains(absoluteLocation)) {
tree.expandPath(path);
}
}
}
restoreSelectionPaths(tree);
}
示例2: expandAll
import javax.swing.JTree; //导入方法依赖的package包/类
private void expandAll(JTree tree, TreePath path, boolean expand) {
TreeNode node = (TreeNode) path.getLastPathComponent();
if (node.getChildCount() >= 0) {
Enumeration enumeration = node.children();
while (enumeration.hasMoreElements()) {
TreeNode n = (TreeNode) enumeration.nextElement();
TreePath p = path.pathByAddingChild(n);
expandAll(tree, p, expand);
}
}
if (expand) {
tree.expandPath(path);
} else {
tree.collapsePath(path);
}
}
示例3: restoreExpandedNodes
import javax.swing.JTree; //导入方法依赖的package包/类
static void restoreExpandedNodes(JTree tree, UIState uiState) {
try {
tree.putClientProperty(UIUtils.PROP_EXPANSION_TRANSACTION, Boolean.TRUE);
Enumeration<TreePath> paths = uiState.getExpandedPaths();
if (paths != null) while (paths.hasMoreElements())
tree.expandPath(paths.nextElement());
} finally {
tree.putClientProperty(UIUtils.PROP_EXPANSION_TRANSACTION, null);
}
}
示例4: 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;
}
示例5: expandAll
import javax.swing.JTree; //导入方法依赖的package包/类
private void expandAll(final JTree tree, final TreePath parent) {
final TreeNode node = (TreeNode) parent.getLastPathComponent();
if (node.getChildCount() >= 0) {
for (@SuppressWarnings("rawtypes")
final Enumeration e = node.children(); e.hasMoreElements();) {
final TreeNode n = (TreeNode) e.nextElement();
final TreePath path = parent.pathByAddingChild(n);
this.expandAll(tree, path);
}
}
tree.expandPath(parent);
// tree.collapsePath(parent);
}
示例6: expandAll
import javax.swing.JTree; //导入方法依赖的package包/类
private void expandAll(JTree tree, TreePath path) {
tree.expandPath(path);
TreeModel model = tree.getModel();
Object lastComponent = path.getLastPathComponent();
for (int i = 0; i < model.getChildCount(lastComponent); i++) {
expandAll(tree,
path.pathByAddingChild(model.getChild(lastComponent, i)));
}
}
示例7: 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);
}
示例8: 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);
}
示例9: expand
import javax.swing.JTree; //导入方法依赖的package包/类
/**
* Expands stored treepaths in JTree
* <p>
* If model has been changed (eg. project change) we
* still try to expand paths whick do not exist.
* We just assume that this is not causing problems,
* and as a side effect it preserved tree expansion status
* even after project has been changed to some other project
* and then back.
* </p>
* <p>
* It is possible that there will be memory leak
* if expanded paths have been removed from model, but
* effect of this is quite insignificant.
* </p>
*/
public void expand(JTree tree){
Iterator iter = expanded.iterator();
while(iter.hasNext()){
tree.expandPath( (TreePath) iter.next() );
}
System.out.println(expanded.size());
}
示例10: expand
import javax.swing.JTree; //导入方法依赖的package包/类
/**
* Expands stored treepaths in JTree
* <p>
* If model has been changed (eg. project change) we
* still try to expand paths whick do not exist.
* We just assume that this is not causing problems,
* and as a side effect it preserved tree expansion status
* even after project has been changed to some other project
* and then back.
* </p>
* <p>
* It is possible that there will be memory leak
* if expanded paths have been removed from model, but
* effect of this is quite insignificant.
* </p>
*/
public void expand(JTree tree){
Iterator iter = expanded.iterator();
while(iter.hasNext()){
tree.expandPath( (TreePath) iter.next() );
}
Util.debug(Integer.toString(expanded.size()));
}