title: jtable cellrenderer changes backgroundcolor of cells while running
body: <p>I'm trying to create a table and color specific cells either yellow, red or white, depending on the content of other columns. For that I am looping through the rows filling in the values and then checking on the contents. that works just fine for every row that is currently displayed on the screen, however when the program reaches rows that are not displayed or if the user try's to scroll every cell changes its backgroundcolor back to white. I have searched the web for solutions and the only idea that sounded reasonable was to reset the cellRenderer after each loop, which does not work because it resets every cell too.</p>
  
  <p>I hope someone knows a solution for this or can give me an idea where i mist out on something.</p>
  
  <p>I am using this loop</p>
  
  <pre><code>for(int e = 0; e &lt; modules.size(); e++)
      {
      gui.clearOutputStream();
      gui.getOutputStream().setText("Load Modul " + modules.get(e) + "\r\n");
      version = getVersion(modules.get(e));
  
      //Update current Row
      updateRow(gui.getReleaseTabelle(), e);
      }
  </code></pre>
  
  <p>which calls this method</p>
  
  <pre><code>public void updateRow(JTable target, int row){
  //...
  //insert Values here
  //...
  CustomRenderer cr = new CustomRenderer();
          cr.tab = target;
          if(!target.getValueAt(row, 2).equals(target.getValueAt(row, 3)))
          {
              cr.Val1 = target.getValueAt(row, 1).toString();
              target.setValueAt("X", row, 1);
          }
          else if(!target.getValueAt(row, 7).equals(""))
          {
              cr.Val1 = target.getValueAt(row, 1).toString();
              target.setValueAt("Y", row, 1);
          }
          else
          {
  
          }
          target.getColumnModel().getColumn(1).setCellRenderer(cr);
  
  }
  </code></pre>
  
  <p>and this is my CustomRenderer</p>
  
  <pre><code>class CustomRenderer extends DefaultTableCellRenderer 
      {
  private static final long serialVersionUID = 6703872492730589499L;
          public String Val1; 
          public JTable tab;
  
          public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column)
          {
              Component cell = super.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column);
  
              if(tab.getValueAt(row, 1).equals("Y")){
                  cell.setBackground(new java.awt.Color(255, 255, 0));
                  tab.setValueAt(Val1, row, 1);
              }
              else if(tab.getValueAt(row, 1).equals("X")){
                  cell.setBackground(new java.awt.Color(255, 50, 50));
                  tab.setValueAt(Val1, row, 1);
              }
              else
              {
                  //do nothing
              }
              return cell;
          }
      }
  </code></pre>