Results 1 to 2 of 2
  1. #1
    Majin is offline Member
    Join Date
    Jul 2011
    Rep Power

    Question Popup usage: SwingWorker Threads?


    I need to popup a warning message if an exception gets caught within the SwingWorker thread I'm currently using. Since it's my understanding that I shouldn't be making component/GUI updates/changes from outside the event dispatcher thread what's the best way to do this?

    I'm thinking it might have something to do with the firePropertyChange method and creating my own property for whether the thread has encountered an error or not. I've never created a property for use with these Listener methods before though and the examples I've read so far are a little confusing. Am I overthinking it? Is there a much simpler way to do this?

  2. #2
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Blog Entries
    Rep Power


    The simplest is to call the Swing code from within the background thread by directly queuing it on the EDT via the SwingUtilities or EventQueue method, invokeLater(...):

    Java Code:
          java.awt.EventQueue.invokeLater(new Runnable() {
             public void run() {
                // call your Swing code here.
    But having said that, using a listener could work too and probably be more elegant (the worker only worries about notifying and the control handles what the GUI should display when notified), and SwingWorkers are so built to make this pretty easy to do.

Similar Threads

  1. SwingWorker Explination
    By aadem in forum Advanced Java
    Replies: 4
    Last Post: 03-22-2011, 06:34 PM
  2. SwingWorker
    By 3.14.TR in forum Threads and Synchronization
    Replies: 3
    Last Post: 03-14-2011, 05:53 PM
  3. Using SwingWorker
    By viking90 in forum New To Java
    Replies: 1
    Last Post: 04-24-2010, 10:17 AM
  4. SwingWorker question
    By cotarelo in forum Threads and Synchronization
    Replies: 16
    Last Post: 03-23-2010, 12:29 PM
  5. swingworker
    By musiigedeo in forum AWT / Swing
    Replies: 1
    Last Post: 07-26-2007, 01:59 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