Results 1 to 4 of 4
  1. #1
    Join Date
    Jan 2009
    Posts
    10
    Rep Power
    0

    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.

  2. #2
    OrangeDog's Avatar
    OrangeDog is offline Senior Member
    Join Date
    Jan 2009
    Location
    Cambridge, UK
    Posts
    838
    Rep Power
    6

    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

  3. #3
    neilcoffey is offline Senior Member
    Join Date
    Nov 2008
    Posts
    286
    Rep Power
    7

    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

  4. #4
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,315
    Blog Entries
    1
    Rep Power
    26

Similar Threads

  1. Use of swingutilities.invokeLater
    By neha_negi in forum AWT / Swing
    Replies: 2
    Last Post: 09-19-2008, 03:48 AM
  2. Creating a Thread using the Runnable interface
    By Java Tip in forum java.lang
    Replies: 0
    Last Post: 04-09-2008, 07:31 PM
  3. Error : Runnable did not complete within 10000ms
    By piyushgpt1 in forum Advanced Java
    Replies: 1
    Last Post: 02-05-2008, 08:04 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
  •