本文整理汇总了Java中javax.swing.tree.TreeModel.getChild方法的典型用法代码示例。如果您正苦于以下问题:Java TreeModel.getChild方法的具体用法?Java TreeModel.getChild怎么用?Java TreeModel.getChild使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类javax.swing.tree.TreeModel
的用法示例。
在下文中一共展示了TreeModel.getChild方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: expandAllPaths
import javax.swing.tree.TreeModel; //导入方法依赖的package包/类
/**
* Opens all paths in the given node and all nodes below that.
*
* @param path
* the tree path to the node to expand
* @param treeModel
* the tree model
* @see JTree#expandPath(TreePath)
*/
protected void expandAllPaths(TreePath path, TreeModel treeModel) {
expandPath(path);
final Object node = path.getLastPathComponent();
final int n = treeModel.getChildCount(node);
for (int index = 0; index < n; index++) {
final Object child = treeModel.getChild(node, index);
expandAllPaths(path.pathByAddingChild(child));
}
}
示例2: SelectionTreeItemListener
import javax.swing.tree.TreeModel; //导入方法依赖的package包/类
public SelectionTreeItemListener(SelectionPanel owner) {
if (owner == null)
throw new IllegalArgumentException();
this.owner = owner;
TreeModel model = owner.getTree().getModel();
Object root = owner.getTree().getModel().getRoot();
ePath = new TreePath(new Object[] { root, model.getChild(root, 0) });
vPath = new TreePath(new Object[] { root, model.getChild(root, 1) });
}
示例3: getSimilarPath
import javax.swing.tree.TreeModel; //导入方法依赖的package包/类
private TreePath getSimilarPath(TreePath oldPath) {
if (oldPath == null || oldPath.getPathCount() < 1) return null;
TreeModel currentModel = getModel();
Object currentRoot = currentModel.getRoot();
if (!currentRoot.equals(oldPath.getPathComponent(0))) return null;
TreePath p = new TreePath(currentRoot);
Object[] op = oldPath.getPath();
Object n = currentRoot;
for (int i = 1; i < op.length; i++) {
Object nn = null;
for (int ii = 0; ii < currentModel.getChildCount(n); ii++) {
Object c = currentModel.getChild(n, ii);
if (c.equals(op[i])) {
nn = c;
break;
}
}
if (nn == null) return null;
n = nn;
p = p.pathByAddingChild(n);
}
return p;
}
示例4: setCurrentSubcategory
import javax.swing.tree.TreeModel; //导入方法依赖的package包/类
void setCurrentSubcategory(String subpath) {
TreeModel mdl = errorTree.getModel();
for (int i = 0; i < mdl.getChildCount(mdl.getRoot()); i++) {
Object child = mdl.getChild(mdl.getRoot(), i);
Object data = ((DefaultMutableTreeNode) child).getUserObject();
if (data instanceof POMErrorFixBase) {
POMErrorFixBase rule = (POMErrorFixBase) data;
if (rule.getConfiguration().getId().equals(subpath)) {
errorTree.setSelectionRow(i);
break;
}
}
}
}
示例5: getChildren
import javax.swing.tree.TreeModel; //导入方法依赖的package包/类
private ArrayList<String> getChildren(TreeModel tree, Object root, String spaces) {
int categoriesCount = tree.getChildCount(root);
ArrayList<String> returnList = new ArrayList<String>();
for (int i = 0; i <= categoriesCount - 1; i++) {
Object actualChild = tree.getChild(root, i);
returnList.add(spaces + actualChild.toString());
if (!tree.isLeaf(actualChild)) {
spaces = "+-" + spaces;
returnList.addAll(getChildren(tree, actualChild, spaces));
spaces = spaces.substring(2);
}
}
return returnList;
}
示例6: getPath
import javax.swing.tree.TreeModel; //导入方法依赖的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;
}
示例7: getNodeCount
import javax.swing.tree.TreeModel; //导入方法依赖的package包/类
private static int getNodeCount(TreeModel model, Object root) {
int count = model.getChildCount(root);
for (int i = 0; i < model.getChildCount(root); i++) {
Object node = model.getChild(root, i);
count += getNodeCount(model, node);
}
return count;
}