Here you can find the source of collapseAllNodes(JTree tree)
public static void collapseAllNodes(JTree tree)
//package com.java2s; //License from project: LGPL import javax.swing.JTree; public class Main { public static void collapseAllNodes(JTree tree) { int row = tree.getRowCount() - 1; while (row >= 0) { tree.collapseRow(row);/*w w w . j a v a 2s .co m*/ row--; } tree.expandRow(0); row = tree.getRowCount() - 1; while (row >= 0) { tree.expandRow(row); row--; } } }