Question

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;  
     }                                  
}
Was it helpful?

Solution

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

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top