title: Change background color of one cell in JTable
body: <blockquote>
    <p><strong>Possible Duplicate:</strong><br>
    <a href="https://stackoverflow.com/questions/7181699/changing-swing-jtable-cell-colors">Changing Swing JTable Cell Colors</a>  </p>
  </blockquote>
  
  
  
  <p>I have developed a swing application which shows a JTable. I want that when the user modify a cell value, the cell modified change color.</p>
  
  <p>This is the code that I run when the user modify a cell:</p>
  
  <pre><code>this.myTable.getColumnModel().getColumn(column).setCellRenderer(new StatusColumnCellRenderer()); 
  </code></pre>
  
  <p>And this is the code of my cell Render class:</p>
  
  <pre><code>public class StatusColumnCellRenderer extends DefaultTableCellRenderer {
  
      @Override
      public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int col) {
  
          //Cells are by default rendered as a JLabel.
          JLabel l = (JLabel) super.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, col);
  
          //Get the status for the current row.
          TableModelLotti tableModel = (TableModelLotti) table.getModel();
  
          if(isSelected)
              l.setBackground(Color.GREEN);
  
          //Return the JLabel which renders the cell.
          return l;
      }
  }
  </code></pre>