Here you can find the source of expandAll(JTree tree, boolean expand)
public static void expandAll(JTree tree, boolean expand)
//package com.java2s; import javax.swing.JTree; import javax.swing.tree.TreeNode; import javax.swing.tree.TreePath; public class Main { public static void expandAll(JTree tree, boolean expand) { TreeNode root = (TreeNode) tree.getModel().getRoot(); expandAll(tree, new TreePath(root), expand); }//from ww w.j a v a2s . c o m public static void expandAll(JTree tree, TreePath parent, boolean expand) { TreeNode node = (TreeNode) parent.getLastPathComponent(); if (node.getChildCount() >= 0) { for (int i = 0; i < node.getChildCount(); i++) { TreeNode childNode = node.getChildAt(i); TreePath path = parent.pathByAddingChild(childNode); expandAll(tree, path, expand); } } if (expand) { tree.expandPath(parent); } else { tree.collapsePath(parent); } } }