Progress bar increment by 1 every 100th of second

Posted by Matthew De'Loughry on Stack Overflow See other posts from Stack Overflow or by Matthew De'Loughry
Published on 2010-04-07T14:53:36Z Indexed on 2010/04/07 15:33 UTC
Read the original article Hit count: 295

Filed under:
|

I'm trying to get a JProgressBar to increment by 1 every 100th of a second, and at the moment I'm using Thread.sleep(100) inside a while statement like so:

    try {
         while (i<=100){
            doTime();

         }
    } catch (InterruptedException ex) {
        Logger.getLogger(SplashScreen.class.getName()).log(Level.SEVERE, null, ex);
    }

public void doTime() throws InterruptedException{


        jLabel1.setText("sleeping");
        Thread.sleep(100);
        jLabel1.setText("start");
        i++;
        pb.setValue(i);
        pb.repaint();

}

and If I debug by doing a System.out.println it displays in real time but the swing GUI freezes until it drops out of the while loop can anyone help?

thanks

matt

© Stack Overflow or respective owner

Related posts about java

Related posts about swing