SwingUtilities.invokeLater

前端 未结 5 1929
遥遥无期
遥遥无期 2020-11-22 09:09

My question is related to SwingUtilities.invokeLater. When should I use it? Do I have to use each time I need to update the GUI components? What does it exactly

5条回答
  •  旧时难觅i
    2020-11-22 10:07

    Every Swing application has at least 2 threads:

    1. The main thread that executes the application
    2. The EDT (Event Dispatching Thread) is a thread that updates the UI (so the UI will not freeze).

    If you want to update the UI you should execute code within the EDT. Methods like SwingUtilities.invokeLater, SwingUtilities.invokeAndWait, EventQueue.invokeLater, EventQueue.invokeAndWait allow you to execute code by the EDT.

提交回复
热议问题