+1 for AWT Event Thread problem.
I assume you have something like this:
1 2 3 4 5 6 7 8 9 10 11 12 13 14
| final JLabel label= new JLabel(); final JButton button= new JButton(); button.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent e) { for(int i=0; i < 100; i++) { label.setText("..."); } } } ); |
This way, Swing/Awt never gets a chance to act upon the desired changes.
Since Swing and multithreading is a complicated matter, you have to write this code like
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28
| final JLabel label= new JLabel(); final JButton button= new JButton(); button.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent e) { new Thread() { public void run() { for(int i=0; i < 100; i++) { SwingUtilities.invokeLater( new Runnable() { public void run() { label.setText("..."); } } ); } } }.start(); } } ); |
So you have the loop outside the AWT event thread and the setText()-calls injected back in the Event queue via SwingUtilities.invokeLater().
You might split the above code up in declared classes instead of inline declarations to make it more readable.
Just calling repaint on the label might work as well, but is not the recommended way of dealing with such kind of things.