Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 7 of 7

Thread: EventQueue.invokeLater VS SwingUtilities.invokeLater

  1. #1
    Junior Member
    Join Date
    Jun 2011
    Location
    Salt Lake City, Utah
    Posts
    15
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default EventQueue.invokeLater VS SwingUtilities.invokeLater

    Can anyone tell me is there a difference between these, is one perfered over the other and why would I want to use one over the other?

  2. #2
    Crazy Cat Lady KevinWorkman's Avatar
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    5,424
    My Mood
    Hungover
    Thanks
    144
    Thanked 636 Times in 540 Posts

    Default Re: EventQueue.invokeLater VS SwingUtilities.invokeLater

    From the SwingUtilities API: SwingUtilities (Java Platform SE 6)

    public static void invokeLater(Runnable doRun)
    ...
    As of 1.3 this method is just a cover for java.awt.EventQueue.invokeLater().
    Useful links: How to Ask Questions the Smart Way | Use Code Tags | Java Tutorials
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

  3. #3
    Junior Member
    Join Date
    Jun 2011
    Location
    Salt Lake City, Utah
    Posts
    15
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: EventQueue.invokeLater VS SwingUtilities.invokeLater

    That's really not helping me. I've always used SwingUtilities.invokeLater(new Runnable); but recently installed Eclipse 3.7 Indigo and with the WindowsBuilder when you build a new JFrame project now it uses EventQueue.invokeLater(new Runnable); Is there a reason for this, or is it just a preference of style.

  4. #4
    Crazy Cat Lady KevinWorkman's Avatar
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    5,424
    My Mood
    Hungover
    Thanks
    144
    Thanked 636 Times in 540 Posts

    Default Re: EventQueue.invokeLater VS SwingUtilities.invokeLater

    Quote Originally Posted by devett View Post
    That's really not helping me. I've always used SwingUtilities.invokeLater(new Runnable); but recently installed Eclipse 3.7 Indigo and with the WindowsBuilder when you build a new JFrame project now it uses EventQueue.invokeLater(new Runnable); Is there a reason for this, or is it just a preference of style.
    What is not helpful about it? The API already answered your question, and I even copied it here for you. There is no difference between the functions, as of 1.3.
    Useful links: How to Ask Questions the Smart Way | Use Code Tags | Java Tutorials
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

  5. #5
    Junior Member
    Join Date
    Jun 2011
    Location
    Salt Lake City, Utah
    Posts
    15
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: EventQueue.invokeLater VS SwingUtilities.invokeLater

    I'm not trying to be arrogant sorry, I'm just trying to learn having come over from the .NET world. I tried to find the link, but I thought I read somewhere yesterday that they said when Swing was introduced SwingUtilities had a problem with possible deadlock on large appications, where the EventQueue would be more reliable. I know they work with the event dispatch thread at least I thought I remember this much. so I came here where I trust the experts. I appriciate your insight and just trying to learn all I can.

  6. #6
    Crazy Cat Lady KevinWorkman's Avatar
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    5,424
    My Mood
    Hungover
    Thanks
    144
    Thanked 636 Times in 540 Posts

    Default Re: EventQueue.invokeLater VS SwingUtilities.invokeLater

    Quote Originally Posted by devett View Post
    I'm not trying to be arrogant sorry, I'm just trying to learn having come over from the .NET world. I tried to find the link, but I thought I read somewhere yesterday that they said when Swing was introduced SwingUtilities had a problem with possible deadlock on large appications, where the EventQueue would be more reliable. I know they work with the event dispatch thread at least I thought I remember this much. so I came here where I trust the experts. I appriciate your insight and just trying to learn all I can.
    It's okay.

    What you're saying may have been true before 1.3, but that was a long time ago. Now, the SwingUtilities methods simply call the EventQueue methods, so they're the same. But people continue to use whichever one they see in the tutorials (I use SwingUtilities), which may have been written before 1.3. But it really doesn't matter.
    Useful links: How to Ask Questions the Smart Way | Use Code Tags | Java Tutorials
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

  7. #7
    Junior Member
    Join Date
    Jun 2011
    Location
    Salt Lake City, Utah
    Posts
    15
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: EventQueue.invokeLater VS SwingUtilities.invokeLater

    Thank you!

Similar Threads

  1. How do I catch a AWT-EventQueue-0
    By aussiemcgr in forum Java Theory & Questions
    Replies: 6
    Last Post: November 5th, 2010, 09:41 PM
  2. updating EDT with thread swingworker/invokeLater ?
    By mdstrauss in forum AWT / Java Swing
    Replies: 0
    Last Post: October 11th, 2009, 04:52 AM
  3. swingworker OR a swingUtilites.invokeLater()
    By mdstrauss in forum AWT / Java Swing
    Replies: 0
    Last Post: October 11th, 2009, 04:50 AM
  4. Replies: 0
    Last Post: October 10th, 2009, 01:25 PM
  5. [SOLVED] Function of javax.swing.SwingUtilities.invokeLater(new Runnable(
    By neo_2010 in forum AWT / Java Swing
    Replies: 2
    Last Post: July 8th, 2009, 04:45 PM