Results 1 to 5 of 5
  1. #1
    Lil_Aziz1's Avatar
    Lil_Aziz1 is offline Senior Member
    Join Date
    Dec 2009
    Location
    United States
    Posts
    343
    Rep Power
    5

    Default SwingUtilities.invokeLater();

    Java Code:
    	public static void main(String[] args) {
    		SwingUtilities.invokeLater(new Runnable() {
    			public void run() {
    				createAndShowGUI();
    			}
    			
    		});
    	}
    and
    Java Code:
    	public static void main(String[] args) {
    		createAndShowGUI();
    	}
    What's the difference? Why invoke the method in a different thread? It showed no difference. :( Any help is appreciated. Thanks in advance.

    Source: http://java.sun.com/docs/books/tutor...LevelDemo.java
    "Experience is what you get when you don't get what you want" (Dan Stanford)
    "Rise and rise again until lambs become lions" (Robin Hood)

  2. #2
    camickr is offline Senior Member
    Join Date
    Jul 2009
    Posts
    1,234
    Rep Power
    7

    Default

    All Swing components should be created on the Event Dispatch Thread (EDT), which is why you should use the invokeLater.

    99% of the time you won't have a problem, but when you do it probably will be random and you will have a hard time debugging the problem. So get in the habbit of creating Swing components properly and save yourself some grief.

    Read the section from the Swing tutorial on Concurrency for more information.

  3. #3
    bigj is offline Member
    Join Date
    Dec 2009
    Posts
    68
    Rep Power
    0

    Default

    have a look at this sir - Threads and Swing

  4. #4
    [RaIdEn] is offline Senior Member
    Join Date
    Oct 2009
    Location
    California,US
    Posts
    201
    Rep Power
    5

    Default

    thats a nice question so after some research i found this article hope it helps you

    Threading with Swing

    Threading with Swing: SwingUtilities.invokeLater

  5. #5
    Lil_Aziz1's Avatar
    Lil_Aziz1 is offline Senior Member
    Join Date
    Dec 2009
    Location
    United States
    Posts
    343
    Rep Power
    5

    Default

    Ah alright. thanks a ton!
    "Experience is what you get when you don't get what you want" (Dan Stanford)
    "Rise and rise again until lambs become lions" (Robin Hood)

Similar Threads

  1. what is SwingUtilities.invokeLater(new Runnable())
    By sivakumar_sakam in forum AWT / Swing
    Replies: 3
    Last Post: 05-06-2009, 04:47 AM
  2. Use of swingutilities.invokeLater
    By neha_negi in forum AWT / Swing
    Replies: 2
    Last Post: 09-19-2008, 02:48 AM

Tags for this Thread

Posting Permissions

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