How do you use the Event Dispatch Thread?

后端 未结 4 1265
夕颜
夕颜 2020-12-09 20:50

I learned about how swing isn\'t thread-safe. Delving deeper, I discovered that every modification to a swing component must be done on the Event Dispatch Thread in order to

4条回答
  •  萌比男神i
    2020-12-09 21:11

    note that any code executed from event handlers is already run in the EDT (the Event in the acronym)

    this means that for general use (while you don't mess with swingworkers and threadpools and such) you are always inside the EDT

    and you can always query if you are in the EDT with SwingUtilities.isEventDispatchThread()

    also note that in your code the call to invokeAndWait will fail and throw an error when you are in the EDT already

提交回复
热议问题