0
如何实现与ProgressBar相关的'updateProgress'相关逻辑以指示复杂背景任务的滚动性能如下。 这意味着与任务相关的服务方法如此复杂,并且很难逐步详细地使用该方法并实现'updateProgress'相关逻辑。 如果有人有一些想法,请让我知道。谢谢。用于复杂背景的JavaFX进度条任务
@FXML
private ProgressBar progressBar;
@Autowired
private DataExportService dataExportService;
private List<Device> deviceList; // User selected device list for export
/*
* Export user selected data
*/
@FXML
public void doExport() {
// Defile the data export concurrent Task
final Task taskExport = new Task<Void>() {
@Override protected Void call() throws Exception {
if(deviceList.size() > 0) {
try {
// How can I implement ProgressBar related 'updateProgress' logic in here ?
// Note: It is so hard to implement ProgressBar related indicator on in side the
// 'exportData()' methods because it is too complicated and it had several
// steps ex: Filter Device related all data, Build a SQL script,
// Write SQL Script to file etc.
dataExportService.exportData(deviceList);
} catch (DataExportException e) {
logger.error(e.getMessage());
}
}
return null;
}
};
// Set task property to ProgressBar
progressBar.progressProperty().bind(taskExport.progressProperty());
// Start data export task
new Thread(taskExport).start();
}
Kalaschni嗨。谢谢回复。问题是我们如何将最大值计算为20,以及如何将此更新进度栏功能与exportData服务方法结合(同步)。谢谢。 – Channa 2014-12-19 01:21:51
你知道我认为的最大值(deviceList.size)...顺便说一句,你可以通过'list.isEmpty()'检查列表是否为空。 – Kalaschni 2014-12-22 08:08:53