I am trying to implement a cellrenderer that changes color depending on the value of an integer. However, the color of the cell changes only when focused on. See picture below.
@Override
public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row,
int column) {
super.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column);
switch (column) {
case 1:this.setFont(this.getFont().deriveFont(Font.BOLD)); break;
case 3:this.setFont(this.getFont().deriveFont(Font.BOLD)); break;
}
if (column == 4 && (Integer)value > 0) {
setForeground(Color.green);
} else {
setForeground(Color.red);
}
return this;
}