Java tutorial
//package com.java2s; import javax.swing.JTree; public class Main { public static void collapseAllNodes(JTree tree) { int row = tree.getRowCount() - 1; while (row > 0) { tree.collapseRow(row); --row; } } }