Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 05-05-2009, 08:37 PM
Member
 
Join Date: Jan 2009
Posts: 9
Rep Power: 0
sivakumar_sakam is on a distinguished road
Question what is SwingUtilities.invokeLater(new Runnable())
please any body tell, what going when following code at executing time?

SwingUtilities.invokeLater(new Runnable() {
public void run(){
new SwingDemo();



Thanks SIR....

Last edited by sivakumar_sakam; 05-05-2009 at 08:40 PM.
Bookmark Post in Technorati
Reply With Quote
  #2 (permalink)  
Old 05-06-2009, 01:16 AM
OrangeDog's Avatar
Senior Member
 
Join Date: Jan 2009
Location: Cambridge, UK
Posts: 838
Rep Power: 2
OrangeDog is on a distinguished road
Default
invokeLater() places an object on the Swing Event Queue. Once all current events on the queue are processed, the run() method of the object will be called, on the event processing thread.

It is used to ensure that all UI updates are concurrency-safe. So situations such as a component's colour changing while it is being painted do not occur.
__________________
Don't forget to mark threads as [SOLVED] and give reps to helpful posts.
How To Ask Questions The Smart Way
Bookmark Post in Technorati
Reply With Quote
  #3 (permalink)  
Old 05-06-2009, 02:30 AM
Senior Member
 
Join Date: Nov 2008
Posts: 275
Rep Power: 2
neilcoffey is on a distinguished road
Default
You essentially use invokeLater() whenever you need to update the UI and your code is not being run directly in response to a UI event (i.e. it's not inside or called directly by an actionPerformed(), mousePressed() etc method). Typically, this means your program has started some thread in the background and that background thread needs to update the UI. Subtly, it also means at the very beginning of your progam before you've started up your UI.

Some articles I've written that may help you:
- Threading with Swing
- SwingUtilities.invokeLater() - further explanation and example
__________________
Neil Coffey
Javamex - Java tutorials and performance info
Bookmark Post in Technorati
Reply With Quote
  #4 (permalink)  
Old 05-06-2009, 05:47 AM
Fubarable's Avatar
Moderator
 
Join Date: Jun 2008
Posts: 6,504
Rep Power: 8
Fubarable is on a distinguished road
Default
edit: spam advertising removed
Bookmark Post in Technorati
Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Use of swingutilities.invokeLater neha_negi AWT / Swing 2 09-19-2008 03:48 AM
Creating a Thread using the Runnable interface Java Tip java.lang 0 04-09-2008 07:31 PM
Error : Runnable did not complete within 10000ms piyushgpt1 Advanced Java 1 02-05-2008 08:04 PM
Creating a Thread (implementing Java Runnable Interface) JavaForums Java Blogs 0 12-19-2007 10:31 AM


All times are GMT +2. The time now is 08:42 AM.



VBulletin, Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2009, Crawlability, Inc.
Copyright ©2006 - 2007, www.java-forums.org