List of utility methods to do JTree Create
Enumeration | createEnumeration(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; |
TreeCellRenderer | createSimpleTreeCellRenderer(ImageIcon icon) create Simple Tree Cell Renderer return createSimpleTreeCellRenderer(null, icon, new JTree().getFont()); |
JTree | createTree() 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; |
void | createTree(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++) { ... |
MutableTreeNode | createTreeNode(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; |