我有一个java桌面应用程序,它检查某些文件的新版本是否可用并要求用户下载它。当用户单击"is"时,问题仍然可见,我不想显示“正在下载,请等待”之类的消息。但我不知道该怎么做...
private void updateAvailable(Stage stage) {
stage.setTitle("A new version is available. Update?");
stage.initStyle(StageStyle.UNDECORATED);
Label label = new Label(stage.getTitle());
label.setStyle("-fx-font-size: 25");
Button yesButton = new Button("YES");
Button noButton = new Button("NO");
HBox buttons = new HBox(10, yesButton, noButton);
buttons.setAlignment(Pos.CENTER);
yesButton.setStyle("-fx-font-weight: bold");
yesButton.setOnAction(event -> downloadFiles());
noButton.setStyle("-fx-font-weight: bold");
noButton.setOnAction(event -> executeApp());
VBox root = new VBox(label, buttons);
root.setAlignment(Pos.CENTER);
root.setSpacing(20);
root.setPadding(new Insets(25));
root.setStyle("-fx-border-color: lightblue");
stage.setScene(new Scene(root));
stage.show();
}
private void downloadFiles(){
updaterService.backupCurrentVersion();
updaterService.downloadNewestVersion();
}
我尝试在下载方法内创建一个新场景(在下载开始之前)并隐藏当前场景,但没有成功,新场景仅在下载完成时闪烁。
做到这一点的最佳方法是什么?我想我误解了场景的工作原理
最佳答案
您可以使用信息对话框来完成此作业。 JavaFX 为此提供了Alert
类。下面的内容可能对您的情况有所帮助:
displayMessage(){
Alert alert = new Alert(AlertType.INFORMATION);
alert.setTitle("Information Dialog");
alert.setHeaderText(null);
alert.setContentText("Downloading, please wait");
alert.showAndWait();
}
上述方法可以包含在下载按钮处理程序中。
您可以在 Oracle's documentation 中找到有关 Alert
类的更多信息。 .
可以包含上面的代码
关于单击按钮后 JavaFX 更改场景,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47409200/