Java tutorial
//package com.java2s; //License from project: Apache License import javax.swing.JTree; import javax.swing.tree.DefaultMutableTreeNode; import javax.swing.tree.TreePath; public class Main { public static void expand(JTree tree, int level) { DefaultMutableTreeNode currentNode = (DefaultMutableTreeNode) tree.getModel().getRoot(); while (currentNode != null) { if (currentNode.getLevel() <= level) { tree.expandPath(new TreePath(currentNode.getPath())); } currentNode = currentNode.getNextNode(); } } }