Results 1 to 6 of 6

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

  1. #1
    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?

  2. #2
    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.

  3. #3
    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

  4. #4
    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);
            }
        }
    );

  5. #5
    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.

  6. #6
    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.

Similar Threads

  1. SwingUtilities class of java
    By Owen Fernandes in forum Software Development
    Replies: 5
    Last Post: 12-02-2010, 07:23 AM
  2. How to use valueOf method in java?
    By KAIRU26 in forum Software Development
    Replies: 4
    Last Post: 28-01-2010, 09:59 PM
  3. Clone method in Java
    By Joyjeet in forum Software Development
    Replies: 5
    Last Post: 16-01-2010, 12:12 AM
  4. What is method overriding and method overloading in java
    By beelow in forum Software Development
    Replies: 3
    Last Post: 17-11-2009, 07:20 AM
  5. Java: How can I call one method in another method?
    By biohazard 76 in forum Software Development
    Replies: 3
    Last Post: 16-07-2009, 07:12 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •