I have a simple JFrame program, I have a JButton and JLabel, JLabel is initialize with some value. on button click I want to execute one process which will take more than 3 seconds, before process starts and ends i want to show process status in JLabel. but it always sets last value assigned to label when process gets executed.
I did some research and was able to solve my problem. Hopefully it'll help those who might run into the same problem. Apparently, Swing component repainting is managed by a RepaintManager class which intercepts all paint requests and calls invokeLater() to process the pending requests on the same dispatch thread. Therefore you have no control over exactly when the repainting occurs. However, the method paintImmediately() can be used to cause a Swing component to get updated immediately.
So in my code, I added the following line immediately after the setText():