title: Coloring JTable row based on a cell value
body: <p>I've been trying to color a complete JTable row with a custom TableCellRenderer but for some reason it's only coloring my first and last cell.</p>
  
  <p>I want to color based on the second and fourth value, in this case: 5 and 10. If the second value is less then the fourth, color it red. If it's equal color it yellow.</p>
  
  <p>As you can see below it works out fine, but for some reason it only colors the first and last cell and I've been banging my head against the wall trying to get this to work.</p>
  
  <p><a href="https://i.stack.imgur.com/pwD3n.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/pwD3n.png" alt="Only the first and last cell are colored of the row"></a></p>
  
  <p>I assume I'm doing something wrong in my overriden getTableCellRendererComponent:</p>
  
  <pre><code>public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int col) {
      super.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, col);
  
      Integer minStock = (Integer) table.getModel().getValueAt(row, 3);
      Integer currentStock = (Integer) table.getModel().getValueAt(row, 1);
  
      if (Objects.equals(minStock, currentStock)) {
          setBackground(Color.YELLOW);
      } else if (minStock &gt; currentStock) {
          setBackground(Color.RED);
      } else {
          setBackground(table.getBackground());
          setForeground(table.getForeground());
      }
  
      return this;
  }
  </code></pre>
  
  <p>If anyone could enlighten me on how to solve this it would be greatly appreciated!</p>