title: TableCellRenderer and how to refresh Cell background without using JTable.repaint()
body: <ul>
  <li><p>is possible to refresh background based on value from outside correctly, without to force for repaint <code>table.repaint();</code></p></li>
  <li><p><a href="https://stackoverflow.com/questions/9607670/how-do-i-correctly-use-custom-renderers-to-paint-specific-cells-in-a-jtable">Based, used and tested with great code made by  kleopatra and Hovercraft Full Of Eels</a></p></li>
  <li><p>valid for Java6/7, because there weren't any changes in APIs</p></li>
  </ul>
  
  <p><img src="https://i.stack.imgur.com/M3LaS.jpg" alt="enter image description here"><img src="https://i.stack.imgur.com/0whRu.jpg" alt="enter image description here"><img src="https://i.stack.imgur.com/smTfm.jpg" alt="enter image description here"></p>
  
  <p>my SSCCE works correctly, repainted by <code>JTable.repaint()</code>   </p>
  
  <pre><code>import java.awt.BorderLayout;
  import java.awt.Color;
  import java.awt.Component;
  import java.awt.GridLayout;
  import javax.swing.DefaultComboBoxModel;
  import javax.swing.JComboBox;
  import javax.swing.JFrame;
  import javax.swing.JPanel;
  import javax.swing.JScrollPane;
  import javax.swing.JTable;
  import javax.swing.SwingUtilities;
  import javax.swing.border.EmptyBorder;
  import javax.swing.table.DefaultTableCellRenderer;
  import javax.swing.table.DefaultTableModel;
  
  public class MyTableAndRenderer {
  
      private JFrame frame = new JFrame();
      private JPanel panel = new JPanel();
      private String[] items = {"Item 1", "Item 2", "Item 3", "Item 4"};
      private DefaultComboBoxModel comboBoxModel = new DefaultComboBoxModel(items);
      private JComboBox combo = new JComboBox(comboBoxModel);
      private JPanel panel1 = new JPanel();
      private String[] columnNames = {"First Name", "Last Name", "Sport",
          "# of Years", "Vegetarian"};
      private Object[][] data = {
          {"Kathy", "Smith", "Item 1", new Integer(5), (false)},
          {"John", "Doe", "Item 1", new Integer(3), (true)},
          {"Sue", "Black", "Item 3", new Integer(2), (false)},
          {"Jane", "White", "Item 3", new Integer(20), (true)},
          {"Joe", "Brown", "Item 3", new Integer(10), (false)}
      };
      private DefaultTableModel model = new DefaultTableModel(data, columnNames) {
          private static final long serialVersionUID = 1L;
  
          @Override
          public Class getColumnClass(int column) {
              return getValueAt(0, column).getClass();
          }
      };
      private JTable table = new JTable(model);
  
      public MyTableAndRenderer() {
          panel.setBorder(new EmptyBorder(10, 0, 2, 0));
          panel.add(combo);
          //@HFOE
          /*table.setDefaultRenderer(Object.class, new 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);
                  String str = combo.getSelectedItem().toString();
                  if (value.toString().equalsIgnoreCase(str)) {
                      setBackground(Color.RED);
                  } else {
                      setBackground(null);
                  }
                  return this;
              }
          });*/
          //@kleopatra
          /*table.setDefaultRenderer(Object.class, new DefaultTableCellRenderer() {
              @Override
              public Component getTableCellRendererComponent(JTable table,
                      Object value, boolean isSelected, boolean hasFocus,
                      int row, int column) {
                  String str = combo.getSelectedItem().toString();
                  if (value.toString().equalsIgnoreCase(str)) {
                      setBackground(Color.RED);
                  } else {
                      setBackground(null);
                  }
                  super.getTableCellRendererComponent(table, value, isSelected,
                          hasFocus, row, column);
                  return this;
              }
          });*/
          table.setDefaultRenderer(Object.class, new 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);
                  String str = combo.getSelectedItem().toString();
                  if (value.toString().equalsIgnoreCase(str)) {
                      setBackground(Color.RED);
                      table.repaint();
                  } else {
                      setBackground(null);
                      table.repaint();
                  }
                  return this;
              }
          });
          table.getTableHeader().setReorderingAllowed(false);
          table.setAutoCreateRowSorter(true);
          table.setPreferredScrollableViewportSize(table.getPreferredSize());
          panel1.setLayout(new GridLayout(1, 1, 10, 10));
          panel1.add(new JScrollPane(table));
          frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
          frame.add(panel, BorderLayout.NORTH);
          frame.add(panel1);
          frame.pack();
          frame.setVisible(true);
      }
  
      public static void main(String[] args) {
          SwingUtilities.invokeLater(new Runnable() {
              @Override
              public void run() {
                  MyTableAndRenderer fs = new MyTableAndRenderer();
              }
          });
      }
  }
  </code></pre>
  
  <p>EDIT</p>
  
  <p>@Devolus wrote Did you test what I posted? I took this snippet from my own working code, I just removed the stuff inbetween as it is not relevant for the answer. I'm using Java 6 here and this works for me.</p>
  
  <pre><code>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);
  
      ... determine the color value ...
  
      cell.setBackground(back);
      cell.setForeground(fore);
  }
  </code></pre>
  
  <ul>
  <li>caused</li>
  </ul>
  
  <p><img src="https://i.stack.imgur.com/2yn7n.jpg" alt="enter image description here"></p>
  
  <ul>
  <li>doesn't matter Java6/7</li>
  </ul>
  
  <p>from code (reason to post an SSCCE)</p>
  
  <pre><code>import java.awt.BorderLayout;
  import java.awt.Color;
  import java.awt.Component;
  import java.awt.GridLayout;
  import javax.swing.DefaultComboBoxModel;
  import javax.swing.JComboBox;
  import javax.swing.JFrame;
  import javax.swing.JPanel;
  import javax.swing.JScrollPane;
  import javax.swing.JTable;
  import javax.swing.SwingUtilities;
  import javax.swing.border.EmptyBorder;
  import javax.swing.table.DefaultTableCellRenderer;
  import javax.swing.table.DefaultTableModel;
  
  public class MyTableAndRenderer {
  
      private JFrame frame = new JFrame();
      private JPanel panel = new JPanel();
      private String[] items = {"Item 1", "Item 2", "Item 3", "Item 4"};
      private DefaultComboBoxModel comboBoxModel = new DefaultComboBoxModel(items);
      private JComboBox combo = new JComboBox(comboBoxModel);
      private JPanel panel1 = new JPanel();
      private String[] columnNames = {"First Name", "Last Name", "Sport",
          "# of Years", "Vegetarian"};
      private Object[][] data = {
          {"Kathy", "Smith", "Item 1", new Integer(5), (false)},
          {"John", "Doe", "Item 1", new Integer(3), (true)},
          {"Sue", "Black", "Item 3", new Integer(2), (false)},
          {"Jane", "White", "Item 3", new Integer(20), (true)},
          {"Joe", "Brown", "Item 3", new Integer(10), (false)}
      };
      private DefaultTableModel model = new DefaultTableModel(data, columnNames) {
          private static final long serialVersionUID = 1L;
  
          @Override
          public Class getColumnClass(int column) {
              return getValueAt(0, column).getClass();
          }
      };
      private JTable table = new JTable(model);
  
      public MyTableAndRenderer() {
          panel.setBorder(new EmptyBorder(10, 0, 2, 0));
          panel.add(combo);
          table.setDefaultRenderer(Object.class, new DefaultTableCellRenderer() {
              @Override
              public Component getTableCellRendererComponent(JTable table,
                      Object value, boolean isSelected, boolean hasFocus,
                      int row, int column) {
                  Component c = super.getTableCellRendererComponent(table, value, isSelected,
                          hasFocus, row, column);
                  String str = combo.getSelectedItem().toString();
                  if (value.toString().equalsIgnoreCase(str)) {
                      c.setBackground(Color.RED);
                  } else {
                      c.setBackground(null);
                  }
                  return this;
              }
          });
          table.getTableHeader().setReorderingAllowed(false);
          table.setAutoCreateRowSorter(true);
          table.setPreferredScrollableViewportSize(table.getPreferredSize());
          panel1.setLayout(new GridLayout(1, 1, 10, 10));
          panel1.add(new JScrollPane(table));
          frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
          frame.add(panel, BorderLayout.NORTH);
          frame.add(panel1);
          frame.pack();
          frame.setVisible(true);
      }
  
      public static void main(String[] args) {
          SwingUtilities.invokeLater(new Runnable() {
              @Override
              public void run() {
                  MyTableAndRenderer fs = new MyTableAndRenderer();
              }
          });
      }
  }
  </code></pre>
  
  <p>EDIT2</p>
  
  <ul>
  <li>from WinXp (for all Win OS don't to use Nimbus, Renderer is there very funny, never seen that, great!!! how is this possible)</li>
  </ul>
  
  <p><img src="https://i.stack.imgur.com/L1nWS.jpg" alt="enter image description here"></p>
  
  <p>EDIT3:</p>
  
  <p>note I'm simplified code as is possible, tested before my question here, then casting Rendering Component to JComponent/JLabel doesn't works too (with JLabel.repaint()/setOpaque())</p>