Results 1 to 3 of 3
  1. #1
    Haarp425 is offline Member
    Join Date
    Jun 2010
    Posts
    2
    Rep Power
    0

    Default Progress bar no updating resolved

    I just wanted to share my solution into making my progress bar work while my program process time consuming method.

    Before, my progress bar won't get updated when the for loop in my time consuming method starts working.

    My solution was to put my time consuming method using SwingWorker. It allows my progress bar to get updated and I can open up another menu.

    Here's my solution.

    somewhere in my code. I used to just call my time consuming method by calling it such as

    ...
    wipeSecure(file, totalNumberofPasses); // call wipeSecure method with file and number of passes as input
    ....


    It fails to update my progress bar while that method is called. Inside my wipeSecure() method, I create the update for my progress bar as the inner loop is finished. I have to wrap the wipeSecure() method using SwingWorker and now I have replaced it with.



    SwingWorker<Void, Void> loadWorker = new SwingWorker<Void, Void>()
    {
    protected Void doInBackground() throws Exception
    {
    // calling my time intensive code below.
    wipeButton.setEnabled(false); // disable wipeButton
    wipeSecure(file, totalNumberofPasses); // call wipeSecure method with file and number of passes as input
    log.append("end of wipe()..... " + "\n");
    return null;
    }

    // the done() method gets called when the background process above is complete.
    // it's called on the EDT.
    protected void done()
    {
    wipeButton.setEnabled(true); // enable wipeButton
    aProgressBar.setValue(0); // set default progress bar
    }
    };

    loadWorker.execute();
    Last edited by Haarp425; 06-24-2010 at 06:50 PM.

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

    Default

    You might not want to call this:
    Java Code:
    wipeButton.setEnabled(false); // disable wipeButton
    inside your doInBackground method as I believe that the code above should be called on the EDT -- the main Swing thread.

    Also, please read my signature link regarding code tags as they'll make your code easier for us to read.

    Luck and welcome!

  3. #3
    Haarp425 is offline Member
    Join Date
    Jun 2010
    Posts
    2
    Rep Power
    0

    Default

    Quote Originally Posted by Fubarable View Post
    You might not want to call this:
    Java Code:
    wipeButton.setEnabled(false); // disable wipeButton
    inside your doInBackground method as I believe that the code above should be called on the EDT -- the main Swing thread.

    Also, please read my signature link regarding code tags as they'll make your code easier for us to read.

    Luck and welcome!
    If I don't include that in there, my wipeButton would get enabled once in a while once the wipeSecure() method is run even though the wipeButton is disabled prior to wipeSecure() being called.

    I'll try your suggestion and remove it from the doInBackground() and continue with my test.

    Thanks.

Similar Threads

  1. HttpServlet Cannot be resolved to a type
    By chizbox in forum Eclipse
    Replies: 3
    Last Post: 07-01-2012, 05:09 PM
  2. Javax.net is not resolved in Eclipse
    By ansh12 in forum Eclipse
    Replies: 0
    Last Post: 07-04-2009, 12:27 PM
  3. Replies: 0
    Last Post: 07-11-2008, 04:52 PM
  4. Replies: 0
    Last Post: 07-11-2008, 04:51 PM
  5. Mark thread RESOLVED.
    By Eranga in forum Suggestions & Feedback
    Replies: 45
    Last Post: 04-02-2008, 10:34 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
  •