title: How can I repaint a label while doing some processing, in Swing?
body: <p>I'm new to Swing and I was trying to do this:</p>
  
  <p>On pressing a JButton, the program will start iterating over hundreds of items, taking 1 second to process each one, and after finishing each one he should update a label to show the number of items already processed.</p>
  
  <p>The problem is, the label's text is not updated until the cycle finishes iterating over all the items.</p>
  
  <p>I searched online and apparently it's because this is running in the same thread, so I created a new thread to process the data and to update the variable to be used in the label (number of processed files).</p>
  
  <p>But it didn't work. Then I even made another thread, which I start after the previous one, that just repaints the label. Still nothing works.</p>
  
  <p>The code is like this:</p>
  
  <pre><code>btnNewButton.addActionListener(new ActionListener() {
          public void actionPerformed(ActionEvent e) {
              try { SwingUtilities.invokeLater(validateFiles); } 
  }); }
  
  Runnable validateFiles = new Runnable() {
  
      @Override
      public void run() {
                   while(x_is_not_100) {
                        processLoadsOfStuff();
                        label.setText(x); }
              }
  };
  </code></pre>
  
  <p>Can you help me with this?</p>