当前位置: 首页>>代码示例>>Java>>正文


Java TreeModel.isLeaf方法代码示例

本文整理汇总了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);
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:39,代码来源:UIUtils.java

示例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;
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:12,代码来源:UIUtils.java

示例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;
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:16,代码来源:NewProjectTest.java

示例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);
}
 
开发者ID:iedadata,项目名称:geomapapp,代码行数:11,代码来源:MapPlaces.java

示例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);
}
 
开发者ID:iedadata,项目名称:geomapapp,代码行数:11,代码来源:XML_Menu.java


注:本文中的javax.swing.tree.TreeModel.isLeaf方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。