List of utility methods to do JTree Node
DefaultMutableTreeNode | addChildNode(DefaultMutableTreeNode parent, Object child) add Child Node HashSet hashSet = new HashSet(); DefaultMutableTreeNode childNode; for (int i = 0; i < parent.getChildCount(); i++) { hashSet.add(parent.getChildAt(i).toString()); if (hashSet.add(child.toString())) { childNode = new DefaultMutableTreeNode(child); parent.insert(childNode, parent.getChildCount()); ... |
DefaultMutableTreeNode | addCloneNode(DefaultMutableTreeNode srcNode, DefaultMutableTreeNode root) add Clone Node DefaultMutableTreeNode clone = new DefaultMutableTreeNode(srcNode.getUserObject()); root.add(clone); for (int i = 0; i < srcNode.getChildCount(); i++) { DefaultMutableTreeNode child = (DefaultMutableTreeNode) srcNode.getChildAt(i); addCloneNode(child, clone); return clone; |
void | ApplyFilter(DefaultMutableTreeNode node, String filter) Apply Filter if (node.getChildCount() == 0) { if (!node.toString().endsWith(filter)) { node.removeFromParent(); return; for (int i = 0; i < node.getChildCount(); i++) { ApplyFilter((DefaultMutableTreeNode) node.getChildAt(i), filter); ... |
DefaultMutableTreeNode | cloneTreeNode(DefaultMutableTreeNode srcNode) clone Tree Node if (srcNode == null) return null; DefaultMutableTreeNode node = new DefaultMutableTreeNode(srcNode.getUserObject()); for (int i = 0; i < srcNode.getChildCount(); i++) { DefaultMutableTreeNode child = (DefaultMutableTreeNode) srcNode.getChildAt(i); addCloneNode(child, node); return node; ... |
void | collapseSubTree(JTree tree, DefaultMutableTreeNode startNode, DefaultTreeModel model) Collapse the subtree starting at startNode node
if (startNode.isLeaf()) { return; for (Enumeration e = startNode.children(); e.hasMoreElements();) { DefaultMutableTreeNode node = (DefaultMutableTreeNode) e.nextElement(); collapseSubTree(tree, node, model); TreePath tp = new TreePath(model.getPathToRoot(startNode)); ... |
boolean | contains(final JTree tree, final TreeNode node) Tests whether a tree contains a given node. return isAncestor(node, (TreeNode) tree.getModel().getRoot());
|
void | copyDMTreeNode(DefaultMutableTreeNode out, DefaultMutableTreeNode in) Makes a deep copy of a gives DMTreeNode. int curDepth = 0; DefaultMutableTreeNode cur = null; DefaultMutableTreeNode new_node = null; DefaultMutableTreeNode curDepthNode = null; cur = in; curDepth = cur.getLevel(); curDepthNode = out; cur = (DefaultMutableTreeNode) cur.getNextNode(); ... |
DefaultMutableTreeNode | createFolderNode(Object userObject) create Folder Node DefaultMutableTreeNode newFolder = new DefaultMutableTreeNode(userObject) { public boolean isLeaf() { return false; }; return newFolder; |
DefaultMutableTreeNode | createSubTreeIfNecessary(TreeModel model, DefaultMutableTreeNode parent, String childName) create Sub Tree If Necessary DefaultMutableTreeNode ret = null; ret = getSubtree(parent, childName); if (ret == null) { ret = new DefaultMutableTreeNode(childName + "(0)"); DefaultTreeModel dtm = (DefaultTreeModel) model; dtm.insertNodeInto(ret, parent, 0); return ret; ... |
void | expandAll(JTree tree, DefaultMutableTreeNode root) Expand all the children nodes of the specified TreeNode. Enumeration<?> nodes = root.children(); while (nodes.hasMoreElements()) { Object node = nodes.nextElement(); if (node instanceof DefaultMutableTreeNode) { TreePath path = new TreePath(((DefaultMutableTreeNode) node).getPath()); if (!tree.isExpanded(path)) { tree.expandPath(path); |