title: Swing JLabel: Force repaint()
body: <p>I am trying to repaint a JLabel dynamically and I can't for the life of me figure out how to do it. The code below will do as expected once I resize the screen but will not execute the code by itself.</p>
  
  <p>The JLabel has a little circle to the left which is drawn in the border region to the left of the text. The color of the circle should change as a function of the health of an FTP connection (not shown). The thread monitoring the FTP connection calls the <code>setStatus(int)</code> method when the health changes.</p>
  
  <p>The circle is painted during initialization of the JLabel, and I am trying to re-execute this code using <code>repaint()</code>. </p>
  
  <p><strong>EDIT:</strong> I have also tried playing with <code>revalidate()</code>, <code>invalidate()</code>, and <code>validate()</code> to no avail.</p>
  
  <p><strong>EDIT:</strong> Thanks for pointing that out, I started by using <code>paintComponent()</code> and changed to <code>paint()</code> when that didn't work. So no glory for giving that as an answer (sorry, take it up with the Oracle)</p>
  
  <pre><code>import java.awt.Color;
  import java.awt.Component;
  import java.awt.Font;
  import java.awt.Graphics;
  
  import javax.swing.BorderFactory;
  import javax.swing.JLabel;
  
  import com.my.package.io.ftp.FTPConnectionListenable;
  
  class StatusLabel extends JLabel implements FTPConnectionListenable {
  
      private Integer status;
  
      // Constructor
      StatusLabel(final String text) {
          super(text);
          setFont(new Font("Dialog", Font.PLAIN, 10));
          setBorder(BorderFactory.createEmptyBorder(0, 10, 0, 0));
      }
  
      @Override
      public void paintComponent(final Graphics g) {
          super.paintComponent(g);
          g.setColor(getColor());
          g.fillArc(0, this.getHeight()/4, 8, 8, 0, 360);
      }
  
      @Override
      public void setStatus (final int status) {
          this.status = status;
          if (status !=0) 
          repaint(); // Doesn't work :(
      }
  
      private Color getColor () {
          switch (status) {
          case FTPConnectionListenable.STATUS_OK:
              return Color.GREEN;
          case FTPConnectionListenable.STATUS_WARNING:
              return Color.ORANGE;
          case FTPConnectionListenable.STATUS_ERROR:
              return Color.RED;
          default: 
              return Color.PINK;
          }
      }
  }
  </code></pre>