Here you can find the source of expandAll(JTree rightTree)
public static void expandAll(JTree rightTree)
//package com.java2s; //License from project: Apache License import java.util.Enumeration; import javax.swing.*; import javax.swing.tree.DefaultMutableTreeNode; import javax.swing.tree.TreeNode; import javax.swing.tree.TreePath; public class Main { public static void expandAll(JTree rightTree) { expandAll(rightTree, new TreePath(((DefaultMutableTreeNode) rightTree.getModel().getRoot()).getPath())); }//from w ww . j ava2 s.c om public static void expandAll(JTree tree, TreePath parent) { TreeNode node = (TreeNode) parent.getLastPathComponent(); if (node.getChildCount() >= 0) { for (Enumeration e = node.children(); e.hasMoreElements();) { TreeNode n = (TreeNode) e.nextElement(); TreePath path = parent.pathByAddingChild(n); expandAll(tree, path); } } tree.expandPath(parent); } }