本文整理汇总了Java中javax.swing.tree.TreeModel.isLeaf方法的典型用法代码示例。如果您正苦于以下问题:Java TreeModel.isLeaf方法的具体用法?Java TreeModel.isLeaf怎么用?Java TreeModel.isLeaf使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类javax.swing.tree.TreeModel
的用法示例。
在下文中一共展示了TreeModel.isLeaf方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: autoExpand
import javax.swing.tree.TreeModel; //导入方法依赖的package包/类
/** Checks give TreePath for the last node, and if it ends with a node with just one child,
* it keeps expanding further.
* Current implementation expands through the first child that is not leaf. To more correctly
* fulfil expected semantics in case maxChildToExpand is > 1, it should expand all paths through
* all children.
*
* @param tree
* @param path
* @param maxChildToExpand
*/
public static void autoExpand(JTree tree, TreePath path, int maxLines, int maxChildToExpand, boolean dontExpandToLeafs) {
TreeModel model = tree.getModel();
Object node = path.getLastPathComponent();
TreePath newPath = path;
int currentLines = 0;
while (currentLines++ < maxLines &&
!model.isLeaf(node) &&
(model.getChildCount(node) > 0) &&
(model.getChildCount(node) <= maxChildToExpand)) {
for (int i = 0; i < model.getChildCount(node); i++) {
node = tree.getModel().getChild(node, i);
if (!model.isLeaf(node)) {
if (dontExpandToLeafs && hasOnlyLeafs(tree, node)) {
break;
}
newPath = newPath.pathByAddingChild(node); // if the leaf is added the path will not expand
break; // from for
}
}
}
tree.expandPath(newPath);
}
示例2: hasOnlyLeafs
import javax.swing.tree.TreeModel; //导入方法依赖的package包/类
public static boolean hasOnlyLeafs(JTree tree, Object node) {
TreeModel model = tree.getModel();
for (int i = 0; i < model.getChildCount(node); i++) {
if (!model.isLeaf(model.getChild(node, i))) {
return false;
}
}
return true;
}
示例3: 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;
}
示例4: closePaths
import javax.swing.tree.TreeModel; //导入方法依赖的package包/类
public void closePaths(JTree tree, TreePath path) {
Object node = path.getLastPathComponent();
TreeModel model = tree.getModel();
if (model.isLeaf(node))
return;
int num = model.getChildCount(node);
for (int i = 0; i < num; i++)
closePaths(tree, path.pathByAddingChild(model.getChild(node, i)));
tree.collapsePath(path);
}
示例5: closePaths
import javax.swing.tree.TreeModel; //导入方法依赖的package包/类
public static void closePaths(JTree tree, TreePath path) {
Object node = path.getLastPathComponent();
TreeModel model = tree.getModel();
if (model.isLeaf(node))
return;
int num = model.getChildCount(node);
for (int i = 0; i < num; i++)
closePaths(tree, path.pathByAddingChild(model.getChild(node, i)));
tree.collapsePath(path);
}