List of utility methods to do JTree Node
ArrayList | toArray(final TreeNode node) To array. final ArrayList<TreeNode> list = new ArrayList<TreeNode>(); list.add(node); final Enumeration children = node.children(); while (children.hasMoreElements()) { final TreeNode nextNode = (TreeNode) children.nextElement(); list.addAll(toArray(nextNode)); return list; ... |
void | treeNodeTest(DefaultMutableTreeNode n) tree Node Test Enumeration enumeration = n.breadthFirstEnumeration(); int count = 0; while (enumeration.hasMoreElements()) { DefaultMutableTreeNode node = (DefaultMutableTreeNode) enumeration.nextElement(); System.out.println(node.getDepth() + node.toString()); count++; System.out.println(count + " nodes in total."); ... |
String | treetoString(final DefaultMutableTreeNode tree, final String indent) treeto String StringBuffer sbuf = new StringBuffer(indent + tree.getUserObject() + "\n"); Enumeration enumerator = tree.children(); while (enumerator.hasMoreElements()) { DefaultMutableTreeNode treeNode = (DefaultMutableTreeNode) enumerator.nextElement(); sbuf.append(treetoString(treeNode, indent + " ")); return sbuf.toString(); |
void | updateAllVisibleNodes(final JTree tree) Updates visual representation of all visible tree nodes. final TreeModel model = tree.getModel(); if (model instanceof DefaultTreeModel) { ((DefaultTreeModel) model).nodeStructureChanged((TreeNode) model.getRoot()); } else { tree.revalidate(); tree.repaint(); |
int | whereToInsertTypeNode(DefaultMutableTreeNode parent, String type) where To Insert Type Node int index = 0; int childCount = parent.getChildCount(); if (childCount == 0) { return index; ArrayList<String> existingNames = new ArrayList<String>(); existingNames.add(type); for (int x = 0; x < childCount; x++) { ... |