for (int r = 0; r < nrows && y < ymax; ++r)
int y = top; for (int r = r0; r <= rn; ++r)
  public void paint(Graphics gfx, JComponent ignored)   {    int ncols = table.getColumnCount();    int nrows = table.getRowCount();    if (nrows == 0 || ncols == 0)      return;    Rectangle clip = gfx.getClipBounds();    TableColumnModel cols = table.getColumnModel();    int height = table.getRowHeight() + table.getRowMargin();    int x0 = 0, y0 = 0;    int x = x0;    int y = y0;    Dimension gap = table.getIntercellSpacing();    int ymax = clip.y + clip.height;    int xmax = clip.x + clip.width;    Rectangle bounds = new Rectangle();    // paint the cell contents    for (int c = 0; c < ncols && x < xmax; ++c)      {        y = y0;        TableColumn col = cols.getColumn(c);        int width = col.getWidth();        int halfGapWidth = gap.width / 2;        int halfGapHeight = gap.height / 2;                for (int r = 0; r < nrows && y < ymax; ++r)          {            bounds.x = x + halfGapWidth;            bounds.y = y + halfGapHeight + 1;            bounds.width = width - gap.width + 1;            bounds.height = height - gap.height;              if (bounds.intersects(clip))              {                paintCell(gfx, r, c, bounds, table.getCellRenderer(r, c));              }              y += height;          }        x += width;      }    // tighten up the x and y max bounds    ymax = y;    xmax = x;    Color grid = table.getGridColor();        // paint vertical grid lines        if (grid != null && table.getShowVerticalLines())      {            x = x0;        Color save = gfx.getColor();        gfx.setColor(grid);        for (int c = 0; c < ncols && x < xmax; ++c)          {            x += cols.getColumn(c).getWidth();            gfx.drawLine(x, y0, x, ymax);          }        gfx.setColor(save);      }    // paint horizontal grid lines        if (grid != null && table.getShowHorizontalLines())      {            y = y0;        Color save = gfx.getColor();        gfx.setColor(grid);        for (int r = 0; r < nrows && y < ymax; ++r)          {            y += height;            gfx.drawLine(x0, y, xmax, y);          }        gfx.setColor(save);      }  }