title: Set background color for particular row of JTable at runtime
body: <p>I am working with netbeans IDE7.4, I am adding rows to the <code>JTable</code> at run-time and now I want to set background color for a particular row.  </p>
  
  <p>Now the problem is that when the value of that row is changed the color of that particular row is not changed and when I scroll up or down the table the changes are applied.</p>
  
  <p>How to refresh the table at run-time? How to set background color of particular row at runtime?</p>
  
  <p>This is renderer class am using for coloring particular row: </p>
  
  <pre><code>public class MyCellRenderer extends javax.swing.table.DefaultTableCellRenderer
      {         
  public java.awt.Component getTableCellRendererComponent(javax.swing.JTable table, java.lang.Object value, boolean isSelected,     boolean hasFocus, int row, int column)
     {
     final java.awt.Component cellComponent = super.getTableCellRendererComponent(table, value, isSelected, hasFocus, row,        column);
  
       Object val=table.getValueAt(row, 2);
       String sval=val.toString();
       sval=sval.replaceAll(":","");
       int ival=Integer.parseInt(sval);
    if(ival==0) 
      {  
          cellComponent.setForeground(Color.black);          
          cellComponent.setBackground(Color.red);              
  
      }      
      else  
      {      
          cellComponent.setBackground(Color.white);      
          cellComponent.setForeground(Color.black);      
      }    
      if (isSelected)
     {
      cellComponent.setForeground(table.getSelectionForeground());                             cellComponent.setBackground(table.getSelectionBackground());
     }
  
  
        return cellComponent;
  
   }
  
  
   }
  </code></pre>
  
  <p>and am assigning to jtable like this : </p>
  
  <pre><code>    newViewTable.setDefaultRenderer(Object.class,new MyCellRenderer());
  </code></pre>
  
  <p>newViewTable is the name of JTable.</p>