Win a copy of Java Concurrency Live Lessons this week in the Threads forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

SwingUtilities.invokeLater()  RSS feed

 
Gregg Bolinger
Ranch Hand
Posts: 15304
6
Chrome IntelliJ IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have read some docs on this method and running Threads in Swing. But could someone explain to me in laymens terms what this does? The method name and function don't seem to mean the same thing to me.
Thanks.
 
Chantal Ackermann
Ranch Hand
Posts: 508
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
As I understand it (maybe wrong), all graphics painting of Swing is done in the main Swing thread, while there is another thread, called the event dispatching thread, where methods are executed that are called for example inside of listeners.
The main point is, I think, that Swing is multithreaded as is, but painting isn't as it seems to be difficult to do multithreaded painting. SwingUtilities.invokeLater ensures that the actions done inside it are executed inside the graphics painting thread. This means all methods concerning directly painting such as changing the appearance of components, populating text components with text etc. should be done in this thread - while all time consuming stuff should be done outside of it, database queries e.g.
One good _short_ article on this is:
http://www.smotricz.com/kabutz/Issue001.html
Chantal
 
Gregg Bolinger
Ranch Hand
Posts: 15304
6
Chrome IntelliJ IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Chantal, that clears it up perfectly. Thank you so much.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!