javamultithreadingswingswingutilities

Can I put more then 1 thread in swingUtilities.invokeLater?


I don't know how to use SwingUtilities.invokeLater precisely, but in my application, the panels run in different Runnables, and swingUtilities.invokeLater accepts Runnables in the argument, but if I put a thread inside the thread of swingUtilities.invokeLater, it will work inside the "SwingUtilities thread-safe AWT/Swing concept"? and can I put more then 1 thread? because I have panels/threads to run inside 1 JFrame.


Solution

  • In Swing only 1 thread (the event dispatch thread) may do updates to the user interface (all Swing UI components of the complete application). Do all the updates on user interface with a runnable that is passed into that invokeLater (or invokeAndWait) method.

    Don't do calculations / other tasks in this runnable, because that can slowdown/block your user interface.

    There is no maximum number of runnables you may pass into that SwingUtilities methods. All of them are executed by the event dispatch thread.