• Post Reply Bookmark Topic Watch Topic
  • New Topic

Does this line prevent the GUI from being slowed down?  RSS feed

 
Jackie Luk
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Does the SwingUtilities.invokeAndWait statement
allow the GUI to continue running while this thread is concurrently running at the same time?
Thanks
Jack

 
Campbell Ritchie
Sheriff
Posts: 53779
128
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
No. You will notice little difference between invokeAndWait and invokeLater until you try to write them. Then you find the invokeAndWait method declares all sorts of checked Exceptions which you have to handle, so it is awkward to use. There is a subtle difference, however. Read the documentation SwingUtilities#invokeAndWait causes the Runnable to be executed synchronously and SwingUtilities#invokeLater causes it to be executed asynchronously. Read the documentation. Don't call invokeAndWait from the EDT. Note that both call the methods of the same name in java.awt.EventQueue.

Neither of them should produce a noticeable difference in execution speed. But you should never use Thread#sleep on the EDT. That will prevent all changes to the GUI until the sleep call is finished. So get rid of line 15. If you need something to occur repeatedly always use a Swing Timer.
 
Darryl Burke
Bartender
Posts: 5167
11
Java Netbeans IDE Opera
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Actually, that code doesn't do anything as the new Thread() { ... declared on line 5 is never start()ed.

Also won't compile as there is no terminating semicolon for that declaration.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!