x += widths[c];
  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();    // Determine the range of cells that are within the clip bounds.    Point p1 = new Point(clip.x, clip.y);    int c0 = table.columnAtPoint(p1);    if (c0 == -1)      c0 = 0;    int r0 = table.rowAtPoint(p1);    if (r0 == -1)      r0 = 0;    Point p2 = new Point(clip.x + clip.width, clip.y + clip.height);    int cn = table.columnAtPoint(p2);    if (cn == -1)      cn = table.getColumnCount() - 1;    int rn = table.rowAtPoint(p2);    if (rn == -1)      rn = table.getRowCount() - 1;    TableColumnModel cmodel = table.getColumnModel();    int [] widths = new int[cn+1];    for (int i = c0; i <=cn ; i++)      {        widths[i] = cmodel.getColumn(i).getWidth();      }        Rectangle bounds = table.getCellRect(r0, c0, false);    bounds.height = table.getRowHeight()+table.getRowMargin();        // The left boundary of the area being repainted.    int left = bounds.x;        // The top boundary of the area being repainted.    int top = bounds.y;        // The bottom boundary of the area being repainted.    int bottom;        // The cell height.    int height = bounds.height;    // paint the cell contents    Color grid = table.getGridColor();        for (int r = r0; r <= rn; ++r)      {        for (int c = c0; c <= cn; ++c)              {            bounds.width = widths[c];                paintCell(gfx, r, c, bounds, table.getCellRenderer(r, c));            bounds.x += widths[c];              }        bounds.y += height;        bounds.x = left;      }    bottom = bounds.y;    // paint vertical grid lines        if (grid != null && table.getShowVerticalLines())      {            Color save = gfx.getColor();        gfx.setColor(grid);        int x = left;                for (int c = c0; c <= cn; ++c)          {            gfx.drawLine(x, top, x, bottom);            x += widths[c];          }        gfx.setColor(save);      }    // paint horizontal grid lines        if (grid != null && table.getShowHorizontalLines())      {            Color save = gfx.getColor();        gfx.setColor(grid);        int y = top;        for (int r = r0; r <= rn; ++r)          {            gfx.drawLine(left, y, p2.x, y);            y += height;          }        gfx.setColor(save);      }  }