title: Java Swing: Animations made using Thread.sleep() not working as expected
body: <p>I am trying to create a sliding menu bar in which the menu bar having initial width of 60px, which grows in width to 260px on the ActionPerformed event of the menu icon button (three small horizontal lines <a href="https://material.io/tools/icons/?icon=menu&amp;style=outline" rel="nofollow noreferrer">Menu Icon</a>) with the following code:</p>
  
  <pre class="lang-java prettyprint-override"><code>private void menuLabelBtnActionPerformed(java.awt.event.ActionEvent evt) {                                             
          if(menuToggle.isSelected()){
              menuToggle.setSelected(false);
              Thread th = new Thread(){
                  public void run(){
                      try{
                          for(int i=259;i&gt;=210;i=i-15){
                              Thread.sleep(1);
                              i--;
                              slideMenuPane.setBounds(slideMenuPane.getX(), slideMenuPane.getY(), i, slideMenuPane.getHeight());
                          }
                          for(int i=210;i&gt;=110;i=i-35){
                              Thread.sleep(1);
                              i--;
                              slideMenuPane.setBounds(slideMenuPane.getX(), slideMenuPane.getY(), i, slideMenuPane.getHeight());
                          }
                          for(int i=110;i&gt;=60;i=i-5){
                              Thread.sleep(1);
                              i--;
                              slideMenuPane.setBounds(slideMenuPane.getX(), slideMenuPane.getY(), i, slideMenuPane.getHeight());
                          }
                      }catch(Exception e){
                          System.out.println(e);      
                      }
                  }
              };
              th.start();
          }
          else{
              menuToggle.setSelected(true);
              Thread th = new Thread(){
                  public void run(){
                      try{
                          for(int i=61;i&lt;=110;i=i+15){
                              Thread.sleep(1);
                              i++;
                              slideMenuPane.setBounds(slideMenuPane.getX(), slideMenuPane.getY(), i, slideMenuPane.getHeight());
                          }
                          for(int i=110;i&lt;=210;i=i+35){
                              Thread.sleep(1);
                              i++;
                              slideMenuPane.setBounds(slideMenuPane.getX(), slideMenuPane.getY(), i, slideMenuPane.getHeight());
                          }
                          for(int i=210;i&lt;=260;i=i+5){
                              Thread.sleep(1);
                              i++;
                              slideMenuPane.setBounds(slideMenuPane.getX(), slideMenuPane.getY(), i, slideMenuPane.getHeight());
                          }
                      }catch(Exception e){
                          System.out.println(e);      
                      }
                  }
              };
              th.start();
          }
      }
  
  </code></pre>
  
  <p>where menuToggle (contained in <code>Other Components</code>) is just used to know if the menu bar is already opened.
  In effect this something like this:</p>
  
  <p><a href="https://i.stack.imgur.com/7ohbo.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/7ohbo.png" alt="Before Clicking the button"></a> 
  <a href="https://i.stack.imgur.com/RFOuh.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/RFOuh.png" alt="After Clicking the button"></a></p>
  
  <p>However, when I click the menu icon button, <strong>there is a blink</strong> before the animation starts, it shows the menu bar with its width to be 60px and it lasts for a millisecond.
  Is there anyway I can remove the blink? </p>