title: JTable colors all cells and not only the specific cell
body: <p>I have a problem with a method that should change the color of one specific cell i a JTable, however all the cells change color.</p>
  
  <p>This is the method I am trying to implement:</p>
  
  <pre><code>public Component cellBG(JTable table, int row, int column)
  {
      TableCellRenderer renderer = table.getCellRenderer(row, column);
      Component c = table.prepareRenderer(renderer, row, column);
  
      Object steak = table.getValueAt(row,column);
  
      if(((String) steak).startsWith("+"))
      {
         c.setBackground(Color.GREEN);
      }
      else if(((String) steak).startsWith("-"))
      {
          c.setBackground(Color.RED);
      }
      else if(((String) steak).startsWith("~"))
      {
          c.setBackground(Color.YELLOW);
      }
      else if(((String) steak).equals(""))
      {
          c.setBackground(Color.WHITE);
      }
  
      return c;
  
  }
  </code></pre>
  
  <p>my table contains 10 columns with 8 rows all containing either +, -, ~, or " ", which should result in a scattered pattern i different colors, however the tabel is colored solid in the last entri which is read.</p>
  
  <p>Ass per request an SSCCE</p>
  
  <pre><code>import java.awt.Component;
  import java.awt.EventQueue;
  import java.awt.Color;
  import java.awt.Font;
  import javax.swing.JScrollPane;
  import javax.swing.JTable;
  import javax.swing.JFrame;
  import javax.swing.table.DefaultTableModel;
  import javax.swing.table.JTableHeader;
  import javax.swing.table.TableCellRenderer;
  
  public class ptf_viewer extends JFrame {
  
      static JTable table;
      static DefaultTableModel model;
  
      public static void main(String[] args) {
          EventQueue.invokeLater(new Runnable() {
              public void run() {
                  try {
                      ptf_viewer frame = new ptf_viewer();
                      frame.setVisible(true);
                  } catch (Exception e) {
                      e.printStackTrace();
                  }
              }
          }); 
      }
  
      public ptf_viewer(){
      getContentPane().setBackground(Color.WHITE);
      setTitle("Portable test file viewing");
      setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
      setBounds(50, 50, 1024, 768);
      getContentPane().setLayout(null);
  
      final String[] columnNames = {"Test 1", "Test 2", "Test 3", "Test 4", "Test 5", "Test 6", "Test 7", "Test 8", "Test 9", "Test 10"};
      final Object[][] data = {
                  {"+","+","","","","~","","","",""},
                  {"-","+","","","","","","","",""},
                  {"+","+","","","~","","","","",""},
                  {"+","+","","","","","~","","",""},
                  {"+","-","","~","","","","","",""},
                  {"+","-","","","","","","","",""},
                  {"+","-","","","","","","","",""},
                  {"-","+","~","","","","","","","+"}
      };
      model = new DefaultTableModel(data, columnNames);
      table = new JTable(data, columnNames);
      table.setModel(model);
      for(int i = 0 ; i &lt; 8 ; i++){
              cellBG(table, i, 9);
      }
      JTableHeader header = table.getTableHeader();
      header.setFont(new Font("Times New Roman", Font.BOLD, 13));
      header.setBackground(Color.black);
      header.setForeground(Color.white);
  
      JScrollPane scrollPane = new JScrollPane(table);
      scrollPane.setSize(988, 618);
      scrollPane.setFont(new Font("Times New Roman", Font.BOLD, 13));
      scrollPane.setLocation(10, 60);
      getContentPane().add(scrollPane);
      }
      public Component cellBG(JTable table, int row, int column)
      {
          TableCellRenderer renderer = table.getCellRenderer(row, column);
          Component c = table.prepareRenderer(renderer, row, column);
  
          Object bøf = table.getValueAt(row,column);
  
          if(((String) bøf).startsWith("+"))
          {
             c.setBackground(Color.GREEN);
          }
          else if(((String) bøf).startsWith("-"))
          {
              c.setBackground(Color.RED);
          }
          else if(((String) bøf).startsWith("~"))
          {
              c.setBackground(Color.YELLOW);
          }
          else if(((String) bøf).equals(""))
          {
              c.setBackground(Color.WHITE);
          }
          return c;
      }
      }
  </code></pre>