Java Swing - running on EDT

前端 未结 4 1503
一整个雨季
一整个雨季 2020-12-06 17:25

I have a couple of questions with regards to Swing and using EDT for GUI updates. I just started reading on this stuff so I am a full beginner in this area:

  1. Wh
4条回答
  •  鱼传尺愫
    2020-12-06 17:58

    1. Basically, every time you use a Swing component or a model of a Swing component, it must be done in the EDT. If you don't, no exception will be raised. It could work, but it could also not work, have erratic behavior, corrupted data, etc.
    2. Every Swing event listener is called in the EDT. Basically, except the main method, every line of code of a Swing application is executed in the EDT by default, unless you explicitely start a thread, use a SwingWorker, or something like that.
    3. yes.
    4. Tasks submitted to SwingUtilities.invokeLater() are executed in the same order as the order they were submitted.
    5. Internally, it uses SwingUtilities.invokeLater() or a similar method. The FutureTask doesn't have anything to do with Swing. It's the SwingWorker that ensures that its done method is executed in the EDT. The doneEDT() method has the following comment: Invokes done on the EDT.

提交回复
热议问题