Java Utililty Methods JTree Node

List of utility methods to do JTree Node

Description

The list of methods to do JTree Node are organized into topic(s).

Method

ArrayListtoArray(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;
...
voidtreeNodeTest(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.");
...
StringtreetoString(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();
voidupdateAllVisibleNodes(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();
intwhereToInsertTypeNode(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++) {
...