List of utility methods to do JTree Expand
void | expandPath(JTree tree, TreePath tp) expand Path Object root = tree.getModel().getRoot();
expandPath(tree, new TreePath(root), tp, 0);
|
void | expandPathOnEdt(final JTree tree, final TreePath path) expand Path On Edt SwingUtilities.invokeLater(new Runnable() { public void run() { tree.expandPath(path); }); |
void | expandPaths(JTree tree, Collection expand Paths if (paths != null) { for (Iterator<TreePath> it = paths.iterator(); it.hasNext();) { TreePath tp = it.next(); expandPath(tree, tp); |
void | expandTree(JTree tree, boolean expand) expand Tree TreeNode root = (TreeNode) tree.getModel().getRoot();
expandAll(tree, new TreePath(root), expand);
|
void | expandTree(JTree tree, TreeNode start, int level) expand Tree for (Enumeration children = start.children(); children.hasMoreElements();) { DefaultMutableTreeNode dtm = (DefaultMutableTreeNode) children.nextElement(); if (!dtm.isLeaf() && dtm.getLevel() <= level) { TreePath tp = new TreePath(dtm.getPath()); tree.expandPath(tp); expandTree(tree, dtm, level); return; |
void | expandTreeLevels(JTree tree, TreePath parent, boolean expand, int desiredLevel) Expands all tree nodes or collapse these level by level. 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); if (desiredLevel > 0) expandTreeLevels(tree, path, expand, desiredLevel - 1); else if (desiredLevel != 0) ... |
void | expandTreePaths(JTree tree, Enumeration Used to restore expansion state of the tree like: Enumeration |
int | fullExpand(JTree tree, TreePath parentPath, int nExpansions) full Expand TreeNode parent = (TreeNode) parentPath.getLastPathComponent(); int count = parent.getChildCount(); for (int i = 0; i < count && nExpansions > 0; ++i) { TreeNode child = parent.getChildAt(i); TreePath childPath = parentPath.pathByAddingChild(child); nExpansions = fullExpand(tree, childPath, nExpansions); tree.expandPath(parentPath); ... |
Collection | getExpandedPaths(JTree tree) get Expanded Paths Collection<TreePath> set = new TreeSet<TreePath>(tpLengthComparator); TreePath root = new TreePath(tree.getModel().getRoot()); if (root != null) { for (Enumeration<TreePath> e = tree.getExpandedDescendants(root); e != null && e.hasMoreElements();) { TreePath tp = e.nextElement(); set.add(tp); return set; |
TreePath[] | getExpandedPaths(JTree tree) Get a copy of the list of expanded tree paths of a tree. ArrayList<TreePath> expandedPaths = new ArrayList<TreePath>(); TreePath rootPath = new TreePath(tree.getModel().getRoot()); Enumeration enumeration = tree.getExpandedDescendants(rootPath); if (enumeration != null) { while (enumeration.hasMoreElements()) { expandedPaths.add((TreePath) enumeration.nextElement()); TreePath[] array = new TreePath[expandedPaths.size()]; expandedPaths.toArray(array); return array; |