且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

Swing线程中的Java操作

更新时间:2023-01-13 18:01:41

其中一种解决方案可能是将可能需要很长时间的操作放在另一个线程中

One of the solutions may be putting that potentially long operation in another thread

是的,不应在EDT上执行长操作(或阻塞操作).

Yes, long operations (or blocking operations) should not execute on the EDT.

因此,您确实需要在单独的线程上执行长时间运行的任务.在 Worker线程和Swing Worker 中查看Swing教程中的部分. >针对该问题的Swing解决方案.

So you do need to execute the long running task on a separated Thread. Check out the section from the Swing tutorial on Worker Threads and Swing Worker for the Swing solution to this problem.

查询执行完毕后,您可以发布"结果,以便在更新Swing组件时在EDT上执行代码.

When your query finishes executing you can "publish" the results so the code is executed on the EDT when the Swing components are updated.