This is mainly in regards to my question here, but I don't understand why Swing Utilities is needed and what it is used for. I'm designing a swing gui and I don't wanna miss out on anything that Swing Utilities might offer. Also could someone could explain what the invokeLater
method does and how it works.
Asked
Active
Viewed 5,213 times
3
-
1Check this [question](http://stackoverflow.com/questions/5780936/java-eventqueue-why-should-everything-be-in-invokelater-method) – Sergey Aslanov Jun 14 '11 at 12:54
1 Answers
6
As stated in the API, SwingUtilities
is a collection of utility methods for Swing. In this case, it is needed to ensure that Swing components are created/modified in the Event Dispatch Thread, or EDT
. Also, as stated in the API, invokeLater
is used when an application thread needs to update the GUI.
You might also want to read up on Concurrency in Swing. Also, a More In-Depth Explanation of invokeLater.

mre
- 43,520
- 33
- 120
- 170
-
does this mean anytime I do a pack(), or touch my frame that it should be inside a new Runnable()? – Grammin Jun 14 '11 at 13:05
-
1@Grammin, not necessarily. only if you're in a separate thread (i.e. one other than the EDT). Swing is not thread-safe, therefore all updates to Swing components should be placed on the `EventQueue`, which `SwingUtilities` enables you to easily do. – mre Jun 14 '11 at 13:05
-
1In many cases you change the properties of a frame or a component in an event listener. All event listener code runs on the EDT so you don't have to worry about this. If your application creates seperate threads, then you need to worry about this. – camickr Jun 14 '11 at 15:23