实现方法进入进度条

时间:2016-06-14 17:04:08

标签: java

这里我有一个Button的动作监听器和一个迭代进度条的方法Bar,如何将该方法实现到进度条中?

我曾尝试过pb.setString(iterator);但显然,它不起作用,因为SetString只接受字符串。

{ 
     "latitude": ...
     "longitude": ...
}

1 个答案:

答案 0 :(得分:0)

我会创建一个SwingWorker

SwingWorker<Void, Void> worker = new SwingWorker<Void, Void>() {
    protected Void doInBackground() {
          //do stuff
          setProgress(progressValue); //when you want to update the progress, do this
    }

}
worker.addPropertyChangeListener(new PropertyChangeListener() { //this runs whenever the progress is changed, to actually set the progress of the JProgressBar
            @Override
            public void propertyChange(PropertyChangeEvent evt) {
                if ("progress" == evt.getPropertyName()) {
                    int progress = (Integer) evt.getNewValue();


                    pb.setValue(progress);

                }
            }

        });
worker.execute();