Java swing UI Threads and event button events

后端 未结 1 1556
无人及你
无人及你 2021-01-24 17:23

So as far as I understood, all the swing components should be created, modified and queried only from the EDT.
So if I happen to press a JButton \"submit\" let\

相关标签:
1条回答
  • 2021-01-24 17:47

    Any action triggered from Swing will run on the EDT. So the code in your actionPerformed method will already be executed on the EDT, without any special handling by you.

    To start a long-running task, like sending data to a server, use a SwingWorker or a Callable and an ExecutorService.

    I prefer using a SwingWorker when implementing a Swing UI, as has it a useful API for publishing updates and makes the callbacks when the task is done automatically happen on the EDT.

    0 讨论(0)
提交回复
热议问题