开发者

set the value of jprogressbar to zero after reached 100%

开发者 https://www.devze.com 2023-02-19 08:24 出处:网络
how to set the value of jprogressbar to zero after reached the 100%? i used the following code but didn\'t do exactly what i want:

how to set the value of jprogressbar to zero after reached the 100%?

i used the following code but didn't do exactly what i want:

private void jButton6ActionPerformed(java.awt.event.ActionEvent evt) {
    // TODO add your handling code here:
    Thread runner = new Thread(){
        @Override
        public void run(){
            counter = pb_MINIMUM;
            while(counter <= pb_MAXIMUM){
                Runnable runme = new Runnable(){
                    public void run(){
                        jProgressBar1.setValue(counter);
                    }
                };
                SwingUtilities.invokeLater(runme);
            开发者_JS百科    counter++;
                try{
                    Thread.sleep(100);
                }catch(Exception e){
                }
            }
        }
    };
    runner.start();
    if(jProgressBar1.getMaximum()==pb_MAXIMUM){
        jProgressBar1.setValue(0);
    }
}

thanks for any help i could get here...


Your call of setValue(0) occurs directly after you started the thread (which does all the work and increases value of progress bar). At this time no work was done yet and the method does not wait for your thread to complete. Instead you may just include the code right after your while loop (same as you do inside but with value of zero).

0

精彩评论

暂无评论...
验证码 换一张
取 消