我的 javafx 桌面应用程序在应用程序初始化期间加载和大文本文件
@Override
public void initialize(URL url, ResourceBundle rb) {
loadAppConfigurationFile();
}
private void loadAppConfigurationFile() {
Task<Void> task = new Task<Void>() {
@Override
public Void call() throws InterruptedException {
//read file and do some operation
return null;
}
};
new Thread(task).start();
}
但这里的问题是我的应用程序 GUI 直到这个过程结束才出现。我在另一个线程中调用了这个文件读取,除了我的 GUI 阶段/场景将首先加载,并且我可以显示一些加载消息,直到该文件加载到系统中。
请告诉我们具体的解决方法。
我尝试这个并且它的工作很容易......在这里bar
是一个进度条
@FXML
void initialize () {
assert bar != null : "fx:id=\"bar\" was not injected: check your FXML file 'Check.fxml'.";
loadAppConfigurationFile();
}
private void loadAppConfigurationFile () {
Task task = new Task<Void>() {
@Override
public Void call() throws InterruptedException {
int max = 1000000;
for (int i = 1; i <= max; i = i + 10) {
if (isCancelled()) {
break;
}
updateProgress(i, max);
System.out.println("somethings is here");
}
return null;
}
};
bar.progressProperty().bind(task.progressProperty());
new Thread(task).start();
}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)