title: using a custom Swing JComponent in a TableCellRenderer
body: <p>OK, I know how to make a simple custom JComponent. I know how to override a TableCellRenderer. I can't seem to combine the two.</p>
  
  <p>Here's a sample <code>JComponent</code> I created:</p>
  
  <pre><code>public static class BarRenderer extends JComponent
  {
      final private double xmin;
      final private double xmax;
      private double xval;
      public BarRenderer(double xmin, double xmax)
      {
          this.xmin=xmin;
          this.xmax=xmax;
      }
  
      @Override protected void paintComponent(Graphics g)
      {
          super.paintComponent(g);
          Rectangle r = g.getClipBounds();
          g.drawRect(r.x, r.y,
                  (int)(r.width * ((xval-xmin)/(xmax-xmin))), r.height);
      }
  
      public void setXval(double x) { 
          this.xval = x;
          repaint();
      }
      public double getXval() { return xval; }
  }
  </code></pre>
  
  <p>It works fine as a standalone JComponent. I call <code>setXval(something)</code> and it updates just fine. (edit: I have a Swing Timer that updates the data periodically)</p>
  
  <p>But if this component is something I return in TableCellRenderer.getTableCellRendererComponent(), then it only repaints when I click on the cell in question. What gives? I must be leaving out something really simple.</p>