Here you can find the source of saveExpansionStateStrings(JTree tree)
public static ArrayList<String> saveExpansionStateStrings(JTree tree)
//package com.java2s; //License from project: Apache License import java.util.ArrayList; import java.util.Enumeration; import javax.swing.JTree; import javax.swing.tree.TreePath; public class Main { public static ArrayList<String> saveExpansionStateStrings(JTree tree) { ArrayList<String> result = new ArrayList<String>(); Enumeration<TreePath> expansionState = tree.getExpandedDescendants(new TreePath(tree.getModel().getRoot())); if (expansionState != null) { while (expansionState.hasMoreElements()) { TreePath treePath = (TreePath) expansionState.nextElement(); result.add(treePath.toString()); }// ww w .j a v a 2 s. c o m } return result; } }