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); }
  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);            }      }  }