我正在尝试将某个时间在某种情况下的前景着色为红色,但正在绘制所有行的前景(应该只有七行)。我做错了什么?代码如下:
class RedRenderer extends DefaultTableCellRenderer{
@Override
public Component getTableCellRendererComponent(JTable table, Object value,boolean isSelected, boolean hasFocus, int row, int column) {
super.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column);
BigDecimal time=new BigDecimal(jTable.getModel().getValueAt(row, 17).toString());
if(time.compareTo(new BigDecimal(2))<=0){
setForeground(Color.red);
setBackground(Color.white);
}else{
setBackground(null);
}
return this;
}
}