这里我有一个Button的动作监听器和一个迭代进度条的方法Bar,如何将该方法实现到进度条中?
我曾尝试过pb.setString(iterator);但显然,它不起作用,因为SetString只接受字符串。
{
"latitude": ...
"longitude": ...
}
答案 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();