I've typically solved this problem by implementing a decorator-style TableCellRenderer implementation that wraps another TableCellRenderer. That way you can retain type-specific renderers for each column, but wrap each of them in the decorator renderer responsible for row highlighting.
Here's an example I wrote that uses this approach to set the background of every alternate row to light grey.
public class AlternateRowRenderer implements TableCellRenderer {
private final TableCellRenderer wrappedRenderer;
public AlternateRowRenderer(TableCellRenderer wrappedRenderer, Color highlightColour) {
this.wrappedRenderer = wrappedRenderer;
}
public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) {
Component ret = wrappedRenderer.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column);
ret.setBackground(getTableBackgroundColour(table, value, isSelected, hasFocus, row, column));
return ret;
}
@SuppressWarnings({"UnusedDeclaration"})
public static Color getTableBackgroundColour(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) {
Color ret;
if (row % 2 != 0) {
ret = isSelected ? ColourUtil.mergeColours(LIGHT_GREY, table.getSelectionBackground(), 0.75) : LIGHT_GREY;
} else {
ret = isSelected ? table.getSelectionBackground() : table.getBackground();
}
return ret;
}
}