Go Back   TechArena Community > Software > Software Development
Become a Member!
Forgot your username/password?
Register Tags Active Topics RSS Search Mark Forums Read

Sponsored Links



What is SwingUtilities.invokeLater(Runnable) method in Java?

Software Development


Reply
 
Thread Tools Search this Thread
  #1  
Old 05-11-2008
Member
 
Join Date: Nov 2008
Posts: 31
What is SwingUtilities.invokeLater(Runnable) method in Java?
  

Can anyone tell me what is SwingUtilities.invokeLater(Runnable) method in Java and how it perfoms?

Reply With Quote
  #2  
Old 05-11-2008
Member
 
Join Date: Oct 2008
Posts: 114
Re: What is SwingUtilities.invokeLater(Runnable) method in Java?

The static utility method invokeLater(Runnable) is intended to execute a new runnable thread from a Swing application without disturbing the normal sequence of event dispatching from the Graphical User Interface (GUI). The method places the runnable object in the queue of Abstract Windowing Toolkit (AWT) events that are due to be processed and returns immediately. The runnable objectís run() method is only called when it reaches the front of the queue. The deferred effect of the invokeLater(Runnable) method ensures that any necessary updates to the user interface can occur immediately, and the runnable work will begin as soon as those high priority events are dealt with. The invoke later method might be used to start work in response to a button click that also requires a significant change to the user interface, perhaps to restrict other activities, while the runnable thread executes.
Reply With Quote
  #3  
Old 05-11-2008
Member
 
Join Date: Nov 2008
Posts: 31
Re: What is SwingUtilities.invokeLater(Runnable) method in Java?

If possible also provide me the Example of SwingUtilities.invokeLater(Runnable) method.

Thanks
Reply With Quote
  #4  
Old 05-11-2008
Member
 
Join Date: Oct 2008
Posts: 167
Re: What is SwingUtilities.invokeLater(Runnable) method in Java?

I will explain you the example, how to implement the SwingUtilities.invokeLater(Runnable) method in the program.

Code:
SwingUtilities.invokeLater(
    new Runnable(){
        public void run(){
            outputArea.append(messageToDisplay);
        }
    }
);
Reply With Quote
  #5  
Old 05-11-2008
Member
 
Join Date: Nov 2008
Posts: 31
Re: What is SwingUtilities.invokeLater(Runnable) method in Java?

what does invokeLater actually do, along with the nested method within it.
Reply With Quote
  #6  
Old 05-11-2008
Member
 
Join Date: Oct 2008
Posts: 137
Re: What is SwingUtilities.invokeLater(Runnable) method in Java?

The Swing Library is not thread safe, which means that only one thread may create or modify swing objects. This is the AWT Event thread. Whenever Swing calls a listener method, it is executed on the AWT Event thread, so you may modify Swing objects here.

InvokeLater causes Swing to run a given runnable when it can on the AWT Event thread. You should use invokeLater any time you want to modify a Swing object outside of a listener method.
Hope this makes you clear with Swing and AWT.
Reply With Quote
Reply

  TechArena Community > Software > Software Development
Tags: , , ,



Thread Tools Search this Thread
Search this Thread:

Advanced Search


Similar Threads for: "What is SwingUtilities.invokeLater(Runnable) method in Java?"
Thread Thread Starter Forum Replies Last Post
SwingUtilities class of java Owen Fernandes Software Development 5 12-02-2010 07:23 AM
How to use valueOf method in java? KAIRU26 Software Development 4 28-01-2010 09:59 PM
Clone method in Java Joyjeet Software Development 5 16-01-2010 12:12 AM
What is method overriding and method overloading in java beelow Software Development 3 17-11-2009 07:20 AM
Java: How can I call one method in another method? biohazard 76 Software Development 3 16-07-2009 07:12 PM


All times are GMT +5.5. The time now is 01:03 AM.