Results 1 to 2 of 2
  1. #1
    Miromancer is offline Member
    Join Date
    Nov 2011
    Rep Power

    Default SwingWorker progress?


    I would like to know if there is any way to get progress even if I want to keep GUI and core separated.
    In the doinBackground() method I call a method from a core class (I load some files and initialize a game). How do I pass the progress to the Worker if time remaining in not known? Or at least I do not know it.

    Here is a snippet:
    Java Code:
      SwingWorker<String, Object> worker = new SwingWorker<String, Object>() {
                        protected String doInBackground() throws Exception {
                            return "Start Game";
    In the GameBegin I call the constructor of the class Game and initialize the whole thing. How do I get progress from the class Game to the main class where the Worker is?

    Thanks for all pieces of advice.


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

    Default Re: SwingWorker progress?

    Since you don't know the time remaining, I can't see how you'll be able to pass it anywhere. Perhaps you are able to get another surrogate marker of completeness such as bytes or files processed? Otherwise about all that I can see you can do based on the code and information provided is to tell the calling code when the SwingWorker has started and when it has finished, and to do that you could add a PropertyChangeListener to the SwingWorker.

Similar Threads

  1. When do I use SwingWorker?
    By TacoManStan in forum AWT / Swing
    Replies: 8
    Last Post: 10-24-2011, 12:40 AM
  2. SwingWorker
    By 3.14.TR in forum Threads and Synchronization
    Replies: 3
    Last Post: 03-14-2011, 04:53 PM
  3. Using SwingWorker
    By viking90 in forum New To Java
    Replies: 1
    Last Post: 04-24-2010, 09:17 AM
  4. SwingWorker question
    By cotarelo in forum Threads and Synchronization
    Replies: 16
    Last Post: 03-23-2010, 11:29 AM
  5. swingworker
    By musiigedeo in forum AWT / Swing
    Replies: 1
    Last Post: 07-26-2007, 12: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