-1

I am trying to color to RED, the foreground when a time is around some condition, but is painting the foreground of ALL rows(should be only seven).What i am doing wrong?Code below:

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;  
     }                                  
}
LeeP
  • 43
  • 1
  • 1
  • 6

1 Answers1

1

Have you tried explicitly setting the foreground color to something different if the current row doesn't match your criteria?

Josh
  • 1,563
  • 11
  • 16
  • You are totally right!It looks like a color memory.I only put setForeground(null); in else and it works fine! – LeeP Oct 06 '13 at 21:37
  • Yeah; `TableCellRenderer`s are used as "rubber stamps" - the attributes of the label used to do the rendering aren't changed (except for the text itself) unless you change them. – Josh Oct 06 '13 at 21:40