title: Repaint() doesn't work when called from new thread
body: <p>I want to do a sorting animation. I've got a <strong>JFrame</strong> with <strong>GridLayout(1,3)</strong> because I have 3 sorting alghorithms. In each cell I have a <strong>JPanel</strong> with <strong>BorderLayout()</strong>. In the <strong>center</strong> of the <strong>JPanel</strong> I have the numbers and for each number a stick with different widths(I placed them horizontally). For each type of sorting I need a thread to call them. So I created class <strong>SortThread</strong> which does my sorting (it extends <strong>JThread</strong>). Each pair of numbers and sticks are painted on the center panel with class <strong>StickNumber</strong> which extends <strong>JLabel</strong>. The problem is when I start the thread. The <strong>repaint()</strong> method doesn't seem to work. </p>
  
  <p>Here is class <strong>SortThread</strong>:</p>
  
  <pre><code>public class SortThread extends Thread{
  private JPanel sortPanel;
  private StickNumber[] listOfNumbers;
  
  public SortThread(JPanel sortPanel)
  {
      this.sortPanel = sortPanel;
      Component[] components = sortPanel.getComponents();
      listOfNumbers = new StickNumber[components.length];
      for(int i = 0; i&lt;components.length; i++)
          listOfNumbers[i] = (StickNumber) components[i];
  }
  
  public SortThread(){}
  
  public void bubbleSort()
  {
      boolean swapped = true;
      int j = 0;
      StickNumber tmp;
  
      while (swapped) {
          swapped = false;
          j++;
          for (int i = 0; i &lt; listOfNumbers.length - j; i++) {                                       
              if (listOfNumbers[i].getValue() &gt; listOfNumbers[i+1].getValue()) {                          
                  tmp = listOfNumbers[i];
                  listOfNumbers[i]=listOfNumbers[i+1];
                  listOfNumbers[i+1]=tmp;
                  swapped = true;
                  sortPanel.validate();
                  sortPanel.repaint();
              }
          }                
      }
  }
  public void run(){
      bubbleSort();
  }
  </code></pre>
  
  <p>Here is the listener for my button which starts the thread:</p>
  
  <pre><code>ActionListener sortListener = new ActionListener(){
  
          @Override
          public void actionPerformed(ActionEvent e) {
              if(sortFlag == false)
              {
                  sortFlag = true;
                  SortThread thread1= new SortThread(centerPanel1);
                  thread1.start();
                  appFrame.validate();
                  appFrame.repaint();
              }
  
          }
      };
      sortButton.addActionListener(sortListener);
  </code></pre>
  
  <p><strong>StickNumber</strong> class:</p>
  
  <pre><code>private void doDrawing(Graphics g) {  
  
      Graphics2D g2 = (Graphics2D) g;
      String number = Integer.toString(value);
      if(dimension!=0)
          setText(number);
      g2.setStroke(new BasicStroke(5));
      g2.draw(new Line2D.Float(dimension*10, 5, height+dimension*10, 5));
  
  }
  
  @Override
  public void paintComponent(Graphics g) {
  
      super.paintComponent(g);
      doDrawing(g);
  }
  </code></pre>