Click here to Skip to main content
15,881,600 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have a JFrame and a label in it.
on button click i have a loop and thread.sleep(100) and I want to show the value of the label in each loop. However the text label is showing the same until the loop is finished and then displaying the final result of the label.
How can I solve this?
Posted
Comments
Prasad Khandekar 4-Jun-13 6:28am    
That's the expected behavior in Swing. For this to work correctly you can use SwingUtilities.invokeLater( Runnable ) or
SwingUtilities.invokeAndWait( Runnable ) so that it will be done on the same thread that Swing itself uses. Even though
you will be using Runnable, you don't have the overhead of actually creating a new Thread since you are just calling the run method on the already existing Swing thread.

Regards,
AlphaDeltaTheta 4-Jun-13 12:19pm    
Should be a solution, and you deserve my +5!
missak boyajian 4-Jun-13 14:37pm    
Hey can you please show a simple example of how it works?
AlphaDeltaTheta 4-Jun-13 23:05pm    
This question is poorly documented... some code?

1 solution

We do not provide code.

Check this example: http://www.java2s.com/Code/JavaAPI/javax.swing/SwingUtilitiesinvokeLaterRunnabledoRun.htm[^]

and develop. Cuase that's what developers do.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900