Alright, so I have an IndirectListModel<MyRow>
allowing for multi-selection of rows that I bind to a JTable
, all cells of which I set the following renderer for:
private static class MyVerificationHighlightingCellRenderer extends DefaultTableCellRenderer {
@Override
public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int rowIndex, int columnIndex) {
super.getTableCellRendererComponent(table, value, isSelected, hasFocus, rowIndex, columnIndex);
MyRow row = ...
if (row.isValid()) {
setBackground(Background.OK);
} else {
setBackground(Background.ERROR);
}
return this;
}
}
This works ... ONLY when the rows are selected.
I.e. I select rows, they turns either green or red, depending on their isValid()
methods. However, as soon as I select something else, the new selection gets the background colours and the others go back to white/ striped.
Why? And more importantly, how can I make my table use the darn colours I want it to have when the rows are NOT selected?