javaswingactionlistenerevent-dispatch-thread

Swing change text of JLabel inside ActionListener


When a button is clicked, it should download certain files, and every time it downloads one, it should update a JLabel to something like "downloading... 2/5". It does not do this, and the frame does not change until the ActionListener is finished.

Based on what I've researched, it seems like the problem is with the event dispatch thread, and the setText requests are queued somewhere without being executed. Is this true? How can I fix this?


Solution

  • You should learn about Threads (Specific tutorial for Java https://www.tutorialspoint.com/java/java_multithreading.htm)