Class AlternateRowColoursJTable

All Implemented Interfaces:
ImageObserver, MenuContainer, Serializable, EventListener, Accessible, CellEditorListener, ListSelectionListener, RowSorterListener, TableColumnModelListener, TableModelListener, Scrollable
Direct Known Subclasses:
JTableForDB

public class AlternateRowColoursJTable
extends JTable
This class provides a simple extension on a JTable, allowing even and uneven rows to have different colours. By default, the uneven row numbers get the default background (corresponding to getUnevenRowColor == null), while the even rows get the colour LIGHT_AQUA, defined as a constant on this class. Both even and uneven row colours can be defined by the caller, where setting the uneven or even rows colours to 'null' results in default behaviour for those columns.
Version:
$Id: AlternateRowColoursJTable.java,v 1.1 2009/08/02 13:23:46 lennart Exp $
Author:
Lennart Martens
See Also:
Serialized Form
  • Field Details

    • AQUA

      public static final Color AQUA
      A rather pronounced AQUA colour (r=183, g=222, b=232).
    • LIGHT_AQUA

      public static final Color LIGHT_AQUA
      A soft-tone AQUA colour (r=219, g=238, b=244). this is the default background colour for even numbered rows.
  • Constructor Details

  • Method Details

    • prepareRenderer

      public Component prepareRenderer​(TableCellRenderer renderer, int rowIndex, int vColIndex)
      Prepares the renderer by querying the data model for the value and selection state of the cell at row, column. Returns the component (may be a Component or a JComponent) under the event location.
      Overrides:
      prepareRenderer in class JTable
      Parameters:
      renderer - the TableCellRenderer to prepare
      rowIndex - the row of the cell to render, where 0 is the first row
      vColIndex - the column of the cell to render, where 0 is the first column
      Returns:
      the Component under the event location
    • setEvenRowColor

      public void setEvenRowColor​(Color aEvenRowColor)
      Sets the colour of the even numbered rows; by default, the LIGHT_AQUA background color will be used.. The default JTable Color can be set by providing a 'null' value here.
      Parameters:
      aEvenRowColor - Color to use for the even numbered rows. Is LIGHT_AQUA by default, and the JTable default Color can be set by specifying 'null' here.
    • setUnevenRowColor

      public void setUnevenRowColor​(Color aUnevenRowColor)
      Sets the colour of the uneven numbered rows; by default, the default JTable background color will be used.. This default JTable background Color can always be set by providing a 'null' value here.
      Parameters:
      aUnevenRowColor - Color to use for the uneven numbered rows. Is the default JTable background by default, and this value can be set by specifying 'null' here.
    • getEvenRowColor

      public Color getEvenRowColor()
      This method returns the Color used for the even numbered rows, or 'null' if the default JTable background color is maintained for these rows.
      Returns:
      Color with the Color used for the even numbered rows, or 'null' if the default JTable background Color is used.
    • getUnevenRowColor

      public Color getUnevenRowColor()
      This method returns the Color used for the uneven numbered rows, or 'null' if the default JTable background color is maintained for these rows.
      Returns:
      Color with the Color used for the uneven numbered rows, or 'null' if the default JTable background Color is used.