本文整理匯總了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);
}