Here you can find the source of getStopRow(JTree tree, int startRow)
private static int getStopRow(JTree tree, int startRow)
//package com.java2s; import javax.swing.JTree; public class Main { 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;//from w ww .j a v a 2s .co m break; } } return stopRow; } }