简体   繁体   中英

How to progressively update a JProgressBar?

I want to get the maximum length for a wave sound, play the track and display its play progress using a JProgressBar. This is what I have done so far but the progress bar is not updating.

Timer t = new Timer(1000,this);

private void playButtonMousePressed(java.awt.event.MouseEvent evt)   {                                        
    // TODO add your handling code here:

   try{
       t.start();
    String track = "tele";
    music = new MusicFunctions(track);
   // music.play(track);

    int progressInit = 0;
    final int len = music.trackLength();
    int tLength = music.trackLength();
    jProgressBar1.setMinimum(0);
    jProgressBar1.setMaximum(len);


    while(i<=len){
    jProgressBar1.setValue(i);
    jProgressBar1.repaint();
    i++;
    }

   }catch(Exception e){
       System.out.println(e);

}                                       
}

See the SwingWorker documentation; the example is even for updating a progress bar: http://docs.oracle.com/javase/6/docs/api/javax/swing/SwingWorker.html .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM