Here you can find the source of getExpandedPaths(JTree tree)
static public Collection<TreePath> getExpandedPaths(JTree tree)
//package com.java2s; import java.util.Collection; import java.util.Comparator; import java.util.Enumeration; import java.util.TreeSet; import javax.swing.JTree; import javax.swing.tree.TreePath; public class Main { public static Comparator<TreePath> tpLengthComparator = new Comparator<TreePath>() { public int compare(TreePath tp1, TreePath tp2) { Object[] a1 = tp1.getPath(); Object[] a2 = tp2.getPath(); int n1 = a1 != null ? a1.length : 0; int n2 = a2 != null ? a2.length : 0; return n1 - n2; }//from w w w . j a v a 2 s .co m }; static public Collection<TreePath> getExpandedPaths(JTree tree) { Collection<TreePath> set = new TreeSet<TreePath>(tpLengthComparator); TreePath root = new TreePath(tree.getModel().getRoot()); if (root != null) { for (Enumeration<TreePath> e = tree.getExpandedDescendants(root); e != null && e.hasMoreElements();) { TreePath tp = e.nextElement(); set.add(tp); } } return set; } }