简体   繁体   English

Swing 在 ActionListener 中更改 JLabel 的文本

[英]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".单击按钮时,它应该下载某些文件,并且每次下载一个文件时,都应该将 JLabel 更新为“正在下载... 2/5”。 It does not do this, and the frame does not change until the ActionListener is finished.它不这样做,并且在 ActionListener 完成之前框架不会改变。

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.根据我的研究,问题似乎出在事件调度线程上,并且 setText 请求在某处排队而没有被执行。 Is this true?这是真的? How can I fix this?我怎样才能解决这个问题?

You should learn about Threads (Specific tutorial for Java https://www.tutorialspoint.com/java/java_multithreading.htm )您应该了解线程(Java https 的具体教程://www.tutorialspoint.com/java/java_multithreading.htm

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM