class ColoredTableCellRenderer extends DefaultTableCellRenderer
{
public Component getTableCellRendererComponent(
JTable table,
Object value,
boolean isSelected,
boolean hasFocus,
int row,
int column)
{
JLabel label = new JLabel((String)value);
label.setOpaque(true);
label.setFont(table.getFont());
label.setForeground(table.getForeground());
label.setBackground(table.getBackground());
if (isSelected)
{
label.setBackground(getSelectionColor());
}
else
if (isRowColor())
{
if (row % 2 == 0)
label.setBackground(getRowColor1());
else
label.setBackground(getRowColor2());
}
label.setHorizontalTextPosition(SwingConstants.CENTER);
label.setVerticalTextPosition(SwingConstants.CENTER);
return label;
}
}