public void collapseTree(){
  for (int i=1; i < tree.getRowCount(); ++i) {
    tree.collapseRow(i);
  }
}

public void collapseTree ( ) { for ( int i = 1 ; i < tree . getRowCount ( ) ; ++ i ) { tree . collapseRow ( i ) ; } }
collapse the tree so that only the root node is visible .
