Results 1 to 4 of 4
  1. #1
    Brad is offline Member
    Join Date
    Feb 2012
    Posts
    20
    Rep Power
    0

    Default Jprogressbar doesn't update as expected

    I have this thread that runs that does nothing more that create a dump file. Sometimes creating this file takes about 15 minutes, so I thought it would be nice to use a jProgressBar so that I could see how far along the process is coming. The problem is that my progress bar never gets updated with anything.

    Granted I have never tried to use jProgressBar so this is probably user error.

    Here is what I have so far....and if there is a better way to put this together let me know. Thanks.

    Java Code:
    final Thread runDump = new Thread(new dumpRepo(command));
             runDump.start();
            
            SwingWorker<Void, Void> worker = new SwingWorker<Void, Void>() {  
                @Override  
                protected Void doInBackground() throws Exception {  
                    int i = 0;  
                    while (runDump.getState() != Thread.State.TERMINATED && i < 100){  
                        try {  
                            synchronized (this) {  
                                wait(1000L);  
                            }  
                            System.out.println(i++);  
                            publish((Void[])null);  
                        } catch (InterruptedException e) {  
                        }  
                    }  
                    System.out.println("Done");  
                    return null;  
                }  
      
                @Override  
                protected void process(List<Void> chunks) {  
                  dump_ProgressBar.setValue(dump_ProgressBar.getValue() + chunks.size());    
                  super.process(chunks);  
                }  
            };  
           worker.execute();           
                    
          }

  2. #2
    jim829 is offline Senior Member
    Join Date
    Jan 2013
    Location
    United States
    Posts
    2,936
    Rep Power
    4

    Default Re: Jprogressbar doesn't update as expected

    Try passing a value of new Void[1] to process. Otherwise, you are essentially passing zero.

    Regards,
    Jim
    The Java™ Tutorial | SSCCE | Java Naming Conventions
    Poor planning our your part does not constitute an emergency on my part.

  3. #3
    Brad is offline Member
    Join Date
    Feb 2012
    Posts
    20
    Rep Power
    0

    Default Re: Jprogressbar doesn't update as expected

    Can I get another hint, I'm not sure I follow you.

  4. #4
    jim829 is offline Senior Member
    Join Date
    Jan 2013
    Location
    United States
    Posts
    2,936
    Rep Power
    4

    Default Re: Jprogressbar doesn't update as expected

    When you call progress, you are passing (Void[]) null. That is still a null, and as such an array of size 0. So you are adding 0 to the progress bar. You need to pass new Void[1] which is an array of size 1.

    Regards,
    Jim
    The Java™ Tutorial | SSCCE | Java Naming Conventions
    Poor planning our your part does not constitute an emergency on my part.

Similar Threads

  1. Replies: 0
    Last Post: 10-11-2013, 02:14 PM
  2. Update doesn't work as expected?
    By RexBox in forum New To Java
    Replies: 3
    Last Post: 10-06-2012, 05:54 PM
  3. Replies: 4
    Last Post: 07-28-2012, 11:13 PM
  4. Replies: 4
    Last Post: 08-23-2010, 03:19 AM
  5. Replies: 1
    Last Post: 11-02-2009, 10:39 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
  •