Java JTree Create createEnumeration(String className, TreeNode root)

Here you can find the source of createEnumeration(String className, TreeNode root)

Description

create Enumeration

License

Open Source License

Declaration

public static Enumeration<TreeNode> createEnumeration(String className, TreeNode root) 

Method Source Code


//package com.java2s;
//License from project: Open Source License 

import java.lang.reflect.Constructor;
import java.util.Enumeration;

import javax.swing.tree.DefaultMutableTreeNode;

import javax.swing.tree.TreeNode;

public class Main {
    public static Enumeration<TreeNode> createEnumeration(String className, TreeNode root) {
        try {//from  w  w  w. j  a v a 2  s  .  c  om
            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) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        return null;
    }
}

Related

  1. createSimpleTreeCellRenderer(ImageIcon icon)
  2. createTree()
  3. createTree(JTree jTree1, String[] leaves)
  4. createTreeNode(String text, int depth)