title: Swing JTable - Highlight selected cell in a different color from rest of the selected row?
body: <p>I have a basic swing JTable and the requirement is that when clicked on any cell, the entire row should be highlighted, and also that the cell which was clicked should be a different color from the rest of the highlighted row.</p>
  
  <p>Currently, I have <em>isRowSelectionAllowed</em> as <em>true</em></p>
  
  <p>I tried using a custom <em>TableCellRenderer</em> which is as follows:</p>
  
  <pre><code>public class CustomTableCellRenderer extends DefaultTableCellRenderer
  {
  
  public static final DefaultTableCellRenderer    DEFAULT_RENDERER    = new DefaultTableCellRenderer();
      @Override
    public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) {
      Component c = DEFAULT_RENDERER.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column);
  
      if (isSelected) {
          c.setBackground(Color.red);
      }
      else {
          c.setForeground(Color.black);
          c.setBackground(Color.white);
      }
      return c;   
    }     
  }
  </code></pre>
  
  <p>But that did not seem to work (entire row was highlighted in red).</p>
  
  <p>I also tried setting the UIManager property as follows:</p>
  
  <pre><code>UIManager.put("Table.focusCellBackground", 
           new javax.swing.plaf.ColorUIResource (Color.red));
  </code></pre>
  
  <p>But that does not seem to work either (even though, when I tried setting a border using</p>
  
  <pre><code>UIManager.put("Table.focusCellHighlightBorder", 
           new BorderUIResource.LineBorderUIResource(Color.red)); 
  </code></pre>
  
  <p>that worked well)</p>
  
  <p>Could you please give any suggestions what I might need to do?</p>