Here you can find the source of fullSelectionCollapse(JTree tree)
public static void fullSelectionCollapse(JTree tree)
//package com.java2s; import javax.swing.JTree; public class Main { public static void fullSelectionCollapse(JTree tree) { int startRow = tree.getLeadSelectionRow(); int stopRow = getStopRow(tree, startRow); for (int i = stopRow - 1; i >= startRow; --i) { tree.collapseRow(i);/*from w w w.j av a2 s . c om*/ } } private static int getStopRow(JTree tree, int startRow) { int startDepth = tree.getPathForRow(startRow).getPathCount(); int last = tree.getRowCount(); int stopRow = last; for (int i = startRow + 1; i < last; ++i) { int depth = tree.getPathForRow(i).getPathCount(); if (depth <= startDepth) { stopRow = i; break; } } return stopRow; } }