コード例 #1
0
  protected void paintGrid(Graphics g, int rowMin, int rowMax, int colMin, int colMax) {
    if (!grid.getShowGrid()) {
      return; // do nothing
    }

    int y1 = grid.getRowPosition(rowMin);
    int y2 = grid.getRowPosition(rowMax) + grid.getRowHeight(rowMax);
    int x1 = grid.getColumnPosition(colMin);
    int x2 = grid.getColumnPosition(colMax) + grid.getColumnWidth(colMax);

    g.setColor(grid.getGridColor());

    // Draw the horizontal lines
    for (int row = rowMin; row <= rowMax; row++) {
      int rowY = grid.getRowPosition(row);
      g.drawLine(x1, rowY, x2, rowY);
    }
    g.drawLine(x1, y2, x2, y2);

    // Draw the vertical gridlines
    for (int col = colMin; col <= colMax; col++) {
      int colX = grid.getColumnPosition(col);
      g.drawLine(colX, y1, colX, y2);
    }
    g.drawLine(x2, y1, x2, y2);
  }
コード例 #2
0
  /** special paint handler for merged cell regions */
  protected void paintSpans(Graphics g, int rowMin, int rowMax, int colMin, int colMax) {
    Rectangle clip = g.getClipBounds();
    Iterator cell = grid.getSpanModel().getSpanIterator();
    while (cell.hasNext()) {
      CellSpan span = (CellSpan) cell.next();
      Rectangle cellBounds = grid.getCellBounds(span.getRow(), span.getColumn());

      // Only paint cell if visible
      if (span.getLastRow() >= rowMin
          && span.getLastColumn() >= colMin
          && span.getFirstRow() <= rowMax
          && span.getFirstColumn() <= colMax) {
        paintCell(g, cellBounds, span.getRow(), span.getColumn());
        // Paint grid line around cell
        if (grid.getShowGrid()) {
          g.setColor(grid.getGridColor());
          g.drawRect(cellBounds.x, cellBounds.y, cellBounds.width, cellBounds.height);
        }
      }
    }
  }