Here you can find the source of expandAll(JTree tree, DefaultMutableTreeNode root)
Parameter | Description |
---|---|
tree | the JTree containing the TreeNodes |
root | the TreeNode to expand the children |
public static void expandAll(JTree tree, DefaultMutableTreeNode root)
//package com.java2s; //License from project: Open Source License import java.util.Enumeration; import javax.swing.JTree; import javax.swing.tree.DefaultMutableTreeNode; import javax.swing.tree.TreePath; public class Main { /**/*from w ww .ja va 2s. c o m*/ * Expand all the children nodes of the specified TreeNode. * * @param tree the JTree containing the TreeNodes * @param root the TreeNode to expand the children */ public static void expandAll(JTree tree, DefaultMutableTreeNode root) { Enumeration<?> nodes = root.children(); while (nodes.hasMoreElements()) { Object node = nodes.nextElement(); if (node instanceof DefaultMutableTreeNode) { TreePath path = new TreePath(((DefaultMutableTreeNode) node).getPath()); if (!tree.isExpanded(path)) { tree.expandPath(path); } } } } }