List of utility methods to do JTree Expand
void | expandAllNodes(JTree tree, TreeNode node) expands all nodes in the tree that descend from node
final TreePath treepath = new TreePath(((DefaultMutableTreeNode) node).getPath()); tree.expandPath(treepath); for (int i = 0; i < node.getChildCount(); i++) { expandAllNodes(tree, node.getChildAt(i)); |
void | expandByExpansionStateStrings(final JTree tree, final TreePath parent, ArrayList expand By Expansion State Strings TreeNode node = (TreeNode) parent.getLastPathComponent(); if (node.getChildCount() >= 0) { for (Enumeration<?> e = node.children(); e.hasMoreElements();) { TreeNode n = (TreeNode) e.nextElement(); TreePath path = parent.pathByAddingChild(n); expandByExpansionStateStrings(tree, path, expansionStateStrings); if (isTreePathContainedInExpansionState(parent, expansionStateStrings)) { tree.expandPath(parent); } else { tree.collapsePath(parent); |
void | expandFirstNode(JTree tree) If expand is true, expands all nodes in the tree. expandFirstNodeAtLevel(getDepth(tree), tree); |
void | expandFirstNodeAtLevel(int level, JTree tree) expand First Node At Level if (level == 0) return; TreeNode root = (TreeNode) tree.getModel().getRoot(); TreePath rootPath = new TreePath(root); TreeNode firstChild = root.getChildAt(0); TreePath path = rootPath.pathByAddingChild(firstChild); tree.expandPath(path); expandNodesAtLevel(level - 1, tree, path); ... |
void | expandFully(JTree tree, TreePath path) expand Fully tree.expandPath(path); TreeNode node = (TreeNode) path.getLastPathComponent(); for (int i = 0; i < node.getChildCount(); i++) { expandFully(tree, path.pathByAddingChild(node.getChildAt(i))); |
int | expandJTreeNode(javax.swing.JTree tree, javax.swing.tree.TreeModel model, Object node, int row, int depth) Expands a given node in a JTree. if (node != null && !model.isLeaf(node)) { tree.expandRow(row); if (depth != 0) { for (int index = 0; row + 1 < tree.getRowCount() && index < model.getChildCount(node); index++) { row++; Object child = model.getChild(node, index); if (child == null) break; ... |
void | expandLevels(JTree tree, int levels, boolean expand) expand Levels TreeModel model = tree.getModel(); if (model == null) { return; TreeNode root = (TreeNode) model.getRoot(); expandLevels(tree, new TreePath(root), levels, expand); |
void | expandNodesAtLevel(int level, JTree tree, TreePath parent) expand Nodes At Level if (level == 0) return; TreeNode node = (TreeNode) parent.getLastPathComponent(); if (node.getChildCount() >= 0) { for (Enumeration<?> e = node.children(); e.hasMoreElements();) { TreeNode n = (TreeNode) e.nextElement(); TreePath path = parent.pathByAddingChild(n); tree.expandPath(path); ... |
void | expandOrCollapseAllRows(final JTree tree, final boolean expand) Expand or collapse every node in the given tree .
if (tree == null) { throw new IllegalArgumentException(new NullPointerException("tree")); expandOrCollapseAllRows(tree, new TreePath(tree.getModel().getRoot()), expand); |
void | expandOrCollapseJTree(JTree tree, boolean expand) Expands a JTree completely Object root = tree.getModel().getRoot();
expandOrCollapseJTree(tree, new TreePath(root), expand);
|