Java tutorial
//package com.java2s; import javax.swing.JTree; import javax.swing.tree.DefaultMutableTreeNode; import javax.swing.tree.TreePath; public class Main { public static void expandTreeNode(JTree tree, DefaultMutableTreeNode node) { expandTreeNode(tree, node, Integer.MAX_VALUE); } public static void expandTreeNode(JTree tree, DefaultMutableTreeNode node, int depth) { if (depth <= 0) { return; } tree.expandPath(new TreePath(node.getPath())); for (int i = 0; i < node.getChildCount(); i++) { expandTreeNode(tree, (DefaultMutableTreeNode) node.getChildAt(i), depth - 1); } } }