title: Updating of JLabel not behaving properly inside SwingWorker thread
body: <p>I am trying to update JLabel in some expected behaviour like -</p>
  
  <p>COND 1 : JLabel should display for 5 seconds , then it should be invisible for next 3 seconds then it should be visible for 5 second and so on.</p>
  
  <p>COND 2 : JLabel should display for 0.5 second , then it should be invisible for next 3 secons..</p>
  
  <p>Kind of any permutation combination , the behaviour should work.
  Following is the sample code-</p>
  
  <pre><code>import java.awt.LayoutManager;
  import java.awt.event.ActionEvent;
  import java.awt.event.ActionListener;
  import java.util.List;
  
  import javax.swing.BoxLayout;
  import javax.swing.JButton;
  import javax.swing.JFrame;
  import javax.swing.JLabel;
  import javax.swing.JPanel;
  import javax.swing.SwingWorker;
  
  public class Main
  {
      static CounterTask task;
  
      public static void main ( String[] args )
      {
  
          final JLabel label = new JLabel( "TEST ME " );
          JButton startButton = new JButton( "Start" );
          startButton.addActionListener( new ActionListener()
          {
              public void actionPerformed ( ActionEvent e )
              {
                  task = new CounterTask( label );
                  task.execute();
              }
          } );
  
          JButton cancelButton = new JButton( "Cancel" );
          cancelButton.addActionListener( new ActionListener()
          {
              public void actionPerformed ( ActionEvent e )
              {
                  task.cancel( true );
              }
          } );
  
          JPanel buttonPanel = new JPanel();
          buttonPanel.add( startButton );
          buttonPanel.add( cancelButton );
  
          JPanel cp = new JPanel();
          LayoutManager layout = new BoxLayout( cp, BoxLayout.Y_AXIS );
          cp.setLayout( layout );
          cp.add( buttonPanel );
          cp.add( label );
  
          JFrame frame = new JFrame();
          frame.setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE );
          frame.setContentPane( cp );
          frame.pack();
          frame.setVisible( true );
      }
  }
  
  class CounterTask
      extends SwingWorker&lt; Integer, Integer &gt;
  {
      int DELAY = 3000;
  
      JLabel label;
  
      int WAIT = 5000;
  
      public CounterTask ( JLabel label )
      {
          this.label = label;
      }
  
      @Override
      protected Integer doInBackground () throws Exception
      {
          int i = 0;
          int count = 1000;
          while ( !isCancelled() &amp;&amp; i &lt; count )
          {
              i++;
              publish( new Integer[] { i } );
              label.setVisible( false );
              Thread.sleep( DELAY );
          }
          return count;
      }
  
      protected void process ( List&lt; Integer &gt; chunks )
      {
          Integer strContent = chunks.get( chunks.size() - 1 );
          label.setVisible( true );
          label.validate();
          label.setText( "DISPLAYING " + strContent );
          try
          {
              Thread.sleep( WAIT );
          }
          catch ( InterruptedException e )
          {
              e.printStackTrace();
          }
      }
  
      @Override
      protected void done ()
      {
          if ( isCancelled() )
              System.out.println( "Cancelled !" );
          else
              System.out.println( "Done !" );
      }
  }
  </code></pre>
  
  <p>I am definately doing something wrong , as this combination works for some data and mostly JLabel becomes invisible throughout , but if I put SOP , I get proper data at proper delay and wait time.</p>
  
  <p>The above code of Swing worker has two variable WAIT , DELAY .
  WAIT makes the JLabel visible for X seconds and DELAY make the JLAbel invisible for Y seconds. But if try with different perm and comb you will realize JLabel visibility not working as expected. It may be because of EDT updates of Label or something to do with repaint. Not sure the root cause.</p>
  
  <p>Expected : </p>
  
  <blockquote>
    <ol>
    <li>Want to make the code work like SOP working or in ideal case.</li>
    <li>Need to know the reason of not behaving properly.</li>
    </ol>
  </blockquote>