Results 1 to 4 of 4
  1. #1
    davigre is offline Member
    Join Date
    Oct 2008
    Posts
    2
    Rep Power
    0

    Smile SwingWorker problem!!! How can I run it 2 times or more?

    Hello!!

    I am new in Java. I use the following code:

    SwingWorker SWorker = new SwingWorker<String, Void>()
    {
    public String doInBackground() {
    return CargarInformacion();
    }

    public void done() {
    try {
    JTextAreaReport.append(get());
    } catch(InterruptedException ie){
    System.out.println(ie.toString());
    } catch(java.util.concurrent.ExecutionException ee){
    System.out.println(ee.toString());
    }
    }
    };

    private String CargarInformacion()
    {
    try {
    in = new BufferedReader(new FileReader(file));
    <read file...>
    }
    return StrMessage;
    }


    The problem is that when this code runs for the first time it works perfect!!! but I need to use it several times with other file names. In the java docs I found the following text:

    "SwingWorker is only designed to be executed once. Executing a SwingWorker more than once will not result in invoking the doInBackground method twice."

    How can I resolve this?

    thank's.

    David.

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

    Default

    First off, I recommend against cross-post questions in multiple forums as this will frustrate anyone who tries to help you only to find out later that the same answer was given hours ago in a cross-posted thread. For this reason, many volunteers here and at the other sites refuse to help repeat offenders.

    Next, it's even worse to do this and not respond to any responses in the other posts. This will not encourage folks to help you further you know if they just assume that you will ignore them.

    If you respond to your posts (and let's keep this in the original post in the Sun Swing forum), someone will help you, guaranteed. Up to you.
    Last edited by Fubarable; 10-02-2008 at 05:09 AM.

  3. #3
    davigre is offline Member
    Join Date
    Oct 2008
    Posts
    2
    Rep Power
    0

    Smile

    ok, I will follow on the original post:

    thank you.

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

    Default

    I've seen no response there to my previous post. ah well, good night and good luck.

Similar Threads

  1. Replies: 2
    Last Post: 02-16-2008, 08:52 PM
  2. presse 1 menuitem execute 4 times the same JFrame
    By marcvb in forum New To Java
    Replies: 0
    Last Post: 12-27-2007, 09:48 PM
  3. Replies: 2
    Last Post: 11-11-2007, 08:07 AM
  4. 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
  •