Difference between SwingUtilities.invokeLater and SwingWorker?

前端 未结 1 1383
有刺的猬
有刺的猬 2020-12-19 21:17

What is the difference between:

    //Some code, takes a bit of time to process
    (new SomeJFrame()).setVisible(true);

    SwingUtilities.invokeLater(new          


        
相关标签:
1条回答
  • 2020-12-19 21:56

    SwingUtilities.invokeLater takes a Runnable and invokoes it in the ui thread later. Usually for short running ui related work.

    SwingWorker runs the main work in a non ui thread - the worker thread. After the long running work is done the done() method is invoked in the ui thread (Event Dispatch Thread).

    But the SwingWorker's doInBackground() method can also publish intermediate results by invoking the publish() method. The SwingWorker will than ensure that the results to publish are processed by the Event Dispatch Thread. You can hook in by implementing the process() method.

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