int rows = treeState.getRowCount();
  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);        // Also paint dashes to the invisible nodes below:        int rows = treeState.getRowCount();        // These should be painted first, otherwise they may cover        // the control icons.        if (endIndex < rows)          for (int i = endIndex + 1; i < rows; i++)            {              TreePath path = treeState.getPathForRow(i);              if (isLastChild(path))                paintVerticalPartOfLeg(g, clip, insets, path);            }        // The two loops are required to ensure that the lines are not        // painted over the other tree components.        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]);          }      }  }