Can't imagine why this isn't already a part of the JTree:
public void expandAllNodes() { int row = 0; while (row < getRowCount()) { expandRow(row); row++; } } public void collapseAllNodes() { int row = getRowCount() - 1; while (row >= 0) { collapseRow(row); row--; } }