Java Code Examples for javax.swing.JTree#collapsePath()
The following examples show how to use
javax.swing.JTree#collapsePath() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: IMContactDoubleClicker.java From SmartIM with Apache License 2.0 | 6 votes |
@Override public void mouseClicked(MouseEvent e) { super.mouseClicked(e); JTree tree = (JTree)e.getSource(); int selRow = tree.getRowForLocation(e.getX(), e.getY()); TreePath selPath = tree.getPathForLocation(e.getX(), e.getY()); if (selRow != -1 && selPath != null) { DefaultMutableTreeNode selectedNode = (DefaultMutableTreeNode)selPath.getLastPathComponent(); if (selectedNode.getChildCount() > 0) { if (tree.isExpanded(selPath)) { tree.collapsePath(selPath); } else { tree.expandPath(selPath); } return; } if (imPanel != null && e.getClickCount() == 2) { imPanel.onDoubleClick(((DefaultMutableTreeNode)selectedNode).getUserObject()); } } }
Example 2
Source File: MainView.java From HiJson with Apache License 2.0 | 6 votes |
private TreePath expandTreeNode(JTree tree,TreeNode[] arr, Boolean expand) { TreePath[] tp = new TreePath[arr.length]; tp[0] = new TreePath(arr[0]); int pos = 0; for (int i = 1; i < arr.length; i++) { tp[i] = tp[i - 1].pathByAddingChild(arr[i]); } for (int i = 0; i < arr.length; i++) { if (expand) { tree.expandPath(tp[i]); } else { tree.collapsePath(tp[i]); } pos = i; } return tp[pos]; }
Example 3
Source File: TDA.java From tda with GNU Lesser General Public License v2.1 | 6 votes |
/** * expand or collapse all nodes of the specified tree * @param tree the tree to expand all/collapse all * @param parent the parent to start with * @param expand expand=true, collapse=false */ private void expandAll(JTree catTree, TreePath parent, boolean expand) { // Traverse children 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); expandAll(catTree, path, expand); } } if(parent.getPathCount() > 1) { // Expansion or collapse must be done bottom-up if (expand) { catTree.expandPath(parent); } else { catTree.collapsePath(parent); } } }
Example 4
Source File: TreeHelpers.java From binnavi with Apache License 2.0 | 6 votes |
private static void expandAll(final JTree tree, final TreePath parent, final boolean expand) { // Traverse children final TreeNode node = (TreeNode) parent.getLastPathComponent(); if (node.getChildCount() >= 0) { for (final Enumeration<?> e = node.children(); e.hasMoreElements();) { final TreeNode n = (TreeNode) e.nextElement(); final TreePath path = parent.pathByAddingChild(n); expandAll(tree, path, expand); } } // Expansion or collapse must be done bottom-up if (expand) { tree.expandPath(parent); } else { tree.collapsePath(parent); } }
Example 5
Source File: TreeUtil.java From Zettelkasten with GNU General Public License v3.0 | 6 votes |
private static void expandAllTrees(TreePath parent, JTree tree) { DefaultMutableTreeNode node = (DefaultMutableTreeNode) parent.getLastPathComponent(); if (node.getChildCount() >= 0) { for (Enumeration e = node.children(); e.hasMoreElements();) { DefaultMutableTreeNode n = (DefaultMutableTreeNode) e.nextElement(); TreePath path = parent.pathByAddingChild(n); expandAllTrees(path, tree); } } // retrieve treenode user object TreeUserObject userObject = (TreeUserObject) node.getUserObject(); // check whether deepest level is reached. if ((expandLevel != -1 && node.getLevel() < expandLevel) || -1 == expandLevel) { // check whether treenode-id is in the list of collapsed items if (userObject != null && collapsedNodes.contains(userObject.getId())) { // if yes, collapse treenode tree.collapsePath(parent); } else { // else expand it tree.expandPath(parent); } } else { tree.collapsePath(parent); } }
Example 6
Source File: View.java From jpexs-decompiler with GNU General Public License v3.0 | 6 votes |
private static void expandTreeNodesRecursive(JTree tree, TreePath parent, boolean expand) { TreeModel model = tree.getModel(); Object node = parent.getLastPathComponent(); int childCount = model.getChildCount(node); for (int j = 0; j < childCount; j++) { Object child = model.getChild(node, j); TreePath path = parent.pathByAddingChild(child); expandTreeNodesRecursive(tree, path, expand); } if (expand) { tree.expandPath(parent); } else { tree.collapsePath(parent); } }
Example 7
Source File: JCompositeRowsSelectorPanel.java From jmeter-plugins with Apache License 2.0 | 6 votes |
private void expandAll(JTree tree, TreePath parent, boolean expand) { // Traverse children 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); expandAll(tree, path, expand); } } // Expansion or collapse must be done bottom-up if (expand) { tree.expandPath(parent); } else { tree.collapsePath(parent); } }
Example 8
Source File: Utils.java From netbeans-mmd-plugin with Apache License 2.0 | 5 votes |
private static void setTreeState(@Nonnull final JTree tree, @Nonnull final TreePath path, final boolean recursively, final boolean unfold) { final Object lastNode = path.getLastPathComponent(); for (int i = 0; i < tree.getModel().getChildCount(lastNode); i++) { final Object child = tree.getModel().getChild(lastNode, i); final TreePath pathToChild = path.pathByAddingChild(child); if (recursively) { setTreeState(tree, pathToChild, recursively, unfold); } } if (unfold) { tree.expandPath(path); } else { tree.collapsePath(path); } }
Example 9
Source File: TreeUtil.java From Zettelkasten with GNU General Public License v3.0 | 5 votes |
private static void expandAllTrees(TreePath parent, boolean expand, JTree tree) { 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); expandAllTrees(path, expand, tree); } } if (expand) { tree.expandPath(parent); } else { tree.collapsePath(parent); } }
Example 10
Source File: TreeUtil.java From nextreports-designer with Apache License 2.0 | 5 votes |
/** * Collapse a tree node and all its child nodes recursively. * * @param tree The tree whose nodes to collapse. * @param path Path to the node to start at. */ public static void collapseAll(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++) { collapseAll(tree, path.pathByAddingChild(model.getChild(node, i))); } tree.collapsePath(path); }