title: Move components in java swing
body: <p>I made a swing application in which i have a grid layout on a Panel, now i have 8 custom buttons on that panel, and two button on left and right for the navigation.</p>
  
  <p>Now my problem is that when i clicked on that navigation buttons i want to move the button in the sliding fashion, for that purpose i set each button location,</p>
  
  <p>But the Jpanel not refresh itself, so it is not visible, If i add the dialog box and click ok then it look as buttons are moving.</p>
  
  <p>How can i do this, i used the revalidate(), and repaint() but it not works.</p>
  
  <p>function which execute on next button click</p>
  
  <pre><code>java.net.URL imageURL = cldr.getResource("images/" +2 + ".png");
                      ImageIcon aceOfDiamonds = new ImageIcon(imageURL);
                      button = new MyButton("ABC", aceOfDiamonds, color[3]);
                      Component buttons[] = jPanel1.getComponents();
                      ArrayList&lt;MyButton&gt; buttons1=new ArrayList&lt;MyButton&gt;();
                      for(int i=0;i&lt;buttons.length;i++)
                      {
                          buttons1.add((MyButton) buttons[i]);
                      }
                      Point p=buttons[0].getLocation();
                      Point p1=buttons[1].getLocation();
                      int dis=p1.x-p.x;
                      System.out.println("Distance--&gt;"+dis);
                      button.setLocation(buttons[buttons.length-1].getLocation().x+dis,buttons[0].getLocation().y);
                      jPanel1.add(button);
                      buttons1.add(button);
                      for(int i=0;i&lt;dis;i++)
                      {
                          for(int btn=0;btn&lt;buttons1.size();btn++)
                          {
                              int currX=buttons1.get(btn).getLocation().x;
                              currX--;
                              buttons1.get(btn).setLocation(currX, buttons1.get(btn).getLocation().y);
                          }
                          try
                          {
                              Thread.sleep(500);
                          }
                          catch (InterruptedException ex)
                          {
                              Logger.getLogger(TestPanel.class.getName()).log(Level.SEVERE, null, ex);
                          }
                          //JOptionPane.showMessageDialog(null,"fds");
                          jPanel1.validate();jPanel1.repaint();
                         }
  </code></pre>
  
  <p>![enter image description here][1]</p>