Results 1 to 4 of 4
  1. #1
    mikeeve is offline Member
    Join Date
    Feb 2009
    Posts
    3
    Rep Power
    0

    Default How to send event from thread to GUI?

    I have a program with multiple threads plus the thread for the Swing frame.

    The frame contains a text field.

    How does another thread tell the Swing thread to change the text?

    I assume the preferred way is to give an event to the text field component with the new text. Correct? Sounds easy, but I can't figure out how to do it. :o

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

    Default

    You use SwingUtilities to help you queue method calls on the EDT:
    Java Code:
    SwingUtilities.invokeLater(new Runnable()
    {
      public void run()
      {
         // .. the method(s) you want to call on Swing widgets
      }
    });

  3. #3
    mikeeve is offline Member
    Join Date
    Feb 2009
    Posts
    3
    Rep Power
    0

    Default

    Thanks. Looks like that will do it.

    Later: OK, it's working in my program now. Onward and upward, one inch at a time...
    Last edited by mikeeve; 03-13-2009 at 01:49 AM.

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

Similar Threads

  1. Difference between Thread.yield() and Thread.sleep() methods
    By Nageswara Rao Mothukuri in forum New To Java
    Replies: 12
    Last Post: 07-30-2010, 06:37 PM
  2. passing a value from parent thread to child thread
    By sachinj13 in forum Threads and Synchronization
    Replies: 7
    Last Post: 09-07-2008, 10:06 PM
  3. data from the main/GUI thread to another runnin thread...
    By cornercuttin in forum Threads and Synchronization
    Replies: 2
    Last Post: 04-23-2008, 11:30 PM
  4. Replies: 0
    Last Post: 01-28-2008, 08:02 AM

Posting Permissions

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