Example usage for javax.swing.tree TreeNode children

List of usage examples for javax.swing.tree TreeNode children

Introduction

In this page you can find the example usage for javax.swing.tree TreeNode children.

Prototype

Enumeration<? extends TreeNode> children();

Source Link

Document

Returns the children of the receiver as an Enumeration.

Usage

From source file:PrintDescendants.java

public static void printDescendants(TreeNode root) {
    System.out.println(root);/*from  w  w w.j  ava 2s .  co  m*/
    Enumeration children = root.children();
    if (children != null) {
        while (children.hasMoreElements()) {
            printDescendants((TreeNode) children.nextElement());
        }
    }
}

From source file:Main.java

public static void visitAllNodes(TreeNode node) {
    System.out.println(node);/*w  w w.  jav  a  2 s  .  c  om*/
    if (node.getChildCount() >= 0) {
        for (Enumeration e = node.children(); e.hasMoreElements();) {
            TreeNode n = (TreeNode) e.nextElement();
            visitAllNodes(n);
        }
    }
}

From source file:MainClass.java

public static void printDescendents(TreeNode root) {
    System.out.println(root);//from   w  ww  .  j  av  a 2 s .  c o m
    Enumeration children = root.children();
    if (children != null) {
        while (children.hasMoreElements()) {
            printDescendents((TreeNode) children.nextElement());
        }
    }
}

From source file:Main.java

public static DefaultMutableTreeNode buscarNodeByNombre(JTree jtree, String nodeStr) {
    DefaultMutableTreeNode node = null;
    TreeNode root = (TreeNode) jtree.getModel().getRoot();
    Enumeration<?> e = root.children();
    while (e.hasMoreElements()) {
        node = (DefaultMutableTreeNode) e.nextElement();
        if ((node.getUserObject().toString()).contains(nodeStr)) {
            return node;
        }/*from  ww w .j  a  v  a  2  s .c o  m*/
    }
    return null;
}

From source file:Main.java

public static void visitAllExpandedNodes(JTree tree, TreePath parent) {
    if (!tree.isVisible(parent)) {
        return;/*  w  ww.j  av a2  s.  c  o  m*/
    }
    TreeNode node = (TreeNode) parent.getLastPathComponent();
    System.out.println(node);

    if (node.getChildCount() >= 0) {
        for (Enumeration e = node.children(); e.hasMoreElements();) {
            TreeNode n = (TreeNode) e.nextElement();
            TreePath path = parent.pathByAddingChild(n);
            visitAllExpandedNodes(tree, path);
        }
    }
}

From source file:TreeUtil.java

public static 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);
        }/* w  w  w . java2 s.c o  m*/
    }
    // Expansion or collapse must be done bottom-up
    if (expand) {
        tree.expandPath(parent);
    } else {
        tree.collapsePath(parent);
    }
}

From source file:Main.java

static 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);
        }//from w w w.  j  a v  a  2s.co  m
    }
    // Expansion or collapse must be done bottom-up
    if (expand) {
        tree.expandPath(parent);
    } else {
        tree.collapsePath(parent);
    }
}

From source file:TreeUtils.java

public static 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);
        }// w  w  w  .j  a  v  a2 s. co  m
    }

    // Expansion or collapse must be done bottom-up
    if (expand) {
        tree.expandPath(parent);
    } else {
        tree.collapsePath(parent);
    }
}

From source file:Main.java

private static void expandAll(JTree tree, TreePath parent, boolean expand) {
    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);
        }/*  ww w.  ja v a 2  s  . c o m*/
    }

    if (expand)
        tree.expandPath(parent);
    else
        tree.collapsePath(parent);
}

From source file:Main.java

private static TreePath find(JTree tree, TreePath parent, Object[] nodes, int depth) {
    TreeNode node = (TreeNode) parent.getLastPathComponent();
    Object o = node;/*  w  ww .  j av a 2 s . c  o m*/

    if (o.equals(nodes[depth])) {
        if (depth == nodes.length - 1) {
            return parent;
        }
        if (node.getChildCount() >= 0) {
            for (Enumeration e = node.children(); e.hasMoreElements();) {
                TreeNode n = (TreeNode) e.nextElement();
                TreePath path = parent.pathByAddingChild(n);
                TreePath result = find(tree, path, nodes, depth + 1);
                if (result != null) {
                    return result;
                }
            }
        }
    }
    return null;
}