Java Utililty Methods JTree Create

List of utility methods to do JTree Create

Description

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

Method

EnumerationcreateEnumeration(String className, TreeNode root)
create Enumeration
try {
    Class clazz = Class.forName("javax.swing.tree.DefaultMutableTreeNode$" + className);
    Constructor constructor = clazz.getDeclaredConstructor(DefaultMutableTreeNode.class, TreeNode.class);
    constructor.setAccessible(true);
    return (Enumeration<TreeNode>) constructor.newInstance(new DefaultMutableTreeNode(), root);
} catch (Exception e) {
    e.printStackTrace();
return null;
TreeCellRenderercreateSimpleTreeCellRenderer(ImageIcon icon)
create Simple Tree Cell Renderer
return createSimpleTreeCellRenderer(null, icon, new JTree().getFont());
JTreecreateTree()
create Tree
DefaultMutableTreeNode top = new DefaultMutableTreeNode("home");
top.add(new DefaultMutableTreeNode("Alice"));
top.add(new DefaultMutableTreeNode("Bob"));
top.add(new DefaultMutableTreeNode("Eve"));
JTree tree = new JTree(top);
return tree;
voidcreateTree(JTree jTree1, String[] leaves)
create Tree
DefaultMutableTreeNode root = new DefaultMutableTreeNode("", true);
jTree1.setModel(new DefaultTreeModel(root));
jTree1.setRootVisible(false);
DefaultMutableTreeNode currentNode = root;
Map<String, DefaultMutableTreeNode> pathList = new HashMap<String, DefaultMutableTreeNode>();
for (int i = 0; i < leaves.length; i++) {
    String[] s = leaves[i].split("/");
    for (int j = 0; j < s.length; j++) {
...
MutableTreeNodecreateTreeNode(String text, int depth)
Creates a random tree of nodes of type MutableTreeNode (actually: DefaultMutableTreeNode).
DefaultMutableTreeNode node = new DefaultMutableTreeNode(text);
if (--depth >= 0)
    for (int i = bellCurve(); --i >= 0;)
        node.add(createTreeNode(createCellValue(), depth));
return node;