int n = endIndex - startIndex + 1; Rectangle[] bounds = new Rectangle[n]; boolean[] isLeaf = new boolean[n]; boolean[] isExpanded = new boolean[n]; TreePath[] path = new TreePath[n]; int k;  k = 0; for (int i = startIndex; i <= endIndex; i++, k++) { path[k] = treeState.getPathForRow(i); isLeaf[k] = treeModel.isLeaf(path[k].getLastPathComponent()); isExpanded[k] = tree.isExpanded(path[k]); bounds[k] = getPathBounds(tree, path[k]);  paintHorizontalPartOfLeg(g, clip, insets, bounds[k], path[k], i, isExpanded[k], false, isLeaf[k]); if (isLastChild(path[k])) paintVerticalPartOfLeg(g, clip, insets, path[k]); }  k = 0; for (int i = startIndex; i <= endIndex; i++, k++) { paintRow(g, clip, insets, bounds[k], path[k], i, isExpanded[k], false, isLeaf[k]); }
  public void paint(Graphics g, JComponent c)  {    JTree tree = (JTree) c;    Rectangle clip = g.getClipBounds();    Insets insets = tree.getInsets();    if (clip != null && treeModel != null)      {        int startIndex = tree.getClosestRowForLocation(clip.x, clip.y);        int endIndex = tree.getClosestRowForLocation(clip.x + clip.width,                                                     clip.y + clip.height);        for (int i = startIndex; i <= endIndex; i++)          {            TreePath path = treeState.getPathForRow(i);            boolean isLeaf = treeModel.isLeaf(path.getLastPathComponent());            boolean isExpanded = tree.isExpanded(path);            Rectangle bounds = getPathBounds(tree, path);            paintHorizontalPartOfLeg(g, clip, insets, bounds, path, i,                                     isExpanded, false, isLeaf);            paintRow(g, clip, insets, bounds, path, i, isExpanded, false,                     isLeaf);            if (isLastChild(path))              paintVerticalPartOfLeg(g, clip, insets, path);          }        // Also paint dashes to the invisible nodes below:        int rows = treeState.getRowCount();        if (endIndex < rows)          for (int i = endIndex + 1; i < rows; i++)            {              TreePath path = treeState.getPathForRow(i);              if (isLastChild(path))                paintVerticalPartOfLeg(g, clip, insets, path);            }      }  }