我很想发布问题,所以如果我发布错误请帮帮我。
我是一名学习Java和Android的学生。目前,我正在使用FXML / Controllers构建JavaFX应用程序。到目前为止,我还没有遇到任何障碍。
我的代码中有一节读取文件,解析它,并将数据放入JavaDB(嵌入式Derby)数据库。这部分工作正常,但如果文件很大,则需要大约15秒才能完成。在此期间,用户可以单击GUI中的其他内容。我想提醒用户并阻止进一步菜单点击直到完成。单击更新按钮时,我创建了一个可见的新窗格,覆盖了控件。它可以工作,但在文件读取完成之前,GUI窗格不会显示。即使窗格可见性代码在文件读取代码之前,它也会执行此操作。我需要在阅读文件之前显示它。
有人可以帮忙吗?
@FXML
AnchorPane paneWait;
@FXML
public void btnUpdateNumberSetHandle(ActionEvent event) {
System.out.println("button: update number set");
// download the file
if (numberSetMetaData.getUrlImport().length() > 0) {
// this turns on the "please wait" pane
// this does not show while file is read
this.paneWait.setVisible(true);
try {
System.out.println("Attempting to download latest numbers from: "+numberSetMetaData.getUrlImport());
URL website = new URL(numberSetMetaData.getUrlImport());
String saveTo = userConfigurations.getTempFilesFolder()+"/numberSet"+numberSetID;
Path tempFolder = Paths.get(saveTo);
Files.copy(website.openStream(), tempFolder, StandardCopyOption.REPLACE_EXISTING);
System.out.println("Successfully saved to: "+saveTo);
// the file is read here and info is saved into database
fileToDatabase.readFileToDatabase(saveTo, numberSetID);
} catch (IOException ex1) {
System.out.println("Problem downloading updated number set from: "+numberSetMetaData.getUrlImport());
ex1.printStackTrace();
}
// this turns off the "please wait" pane
this.paneWait.setVisible(false);
}
}