Interface GridCellRenderer

All Known Implementing Classes:
DefaultGridCellRenderer

public interface GridCellRenderer

Paints the cells of a DataGrid column.

A renderer draws straight into the grid's graphics. There is no component per cell, which is what lets a grid show a million rows: only the cells on screen are painted, and each costs what its drawing costs. The row's background is already painted when paint is called.

DataGrid grid = new DataGrid(new DefaultTableModel(new String[]{"Item", "Balance"},
        new Object[][]{{"rent", -1200}, {"salary", 4000}}, false));
grid.getColumn(1).setRenderer(new DefaultGridCellRenderer() {
    protected int textColor(GridCell cell, int defaultColor) {
        Object v = cell.getValue();
        return v instanceof Number && ((Number) v).doubleValue() < 0 ? 0xc62828 : defaultColor;
    }
});
  • Method Summary

    Modifier and Type
    Method
    Description
    int
    The width, in pixels, the cell's content needs, for a column that sizes itself to what it shows.
    void
    paint(Graphics g, GridCell cell, int x, int y, int width, int height)
    Paints a cell into the rectangle x, y, width, height.
  • Method Details

    • paint

      void paint(Graphics g, GridCell cell, int x, int y, int width, int height)
      Paints a cell into the rectangle x, y, width, height. The graphics is clipped to it.
    • getPreferredWidth

      int getPreferredWidth(GridCell cell)
      The width, in pixels, the cell's content needs, for a column that sizes itself to what it shows.