gpt4 book ai didi

java - 打开弹窗时程序闪烁

转载 作者:行者123 更新时间:2023-11-30 10:39:13 25 4
gpt4 key购买 nike

创建了一个全屏应用程序,在按下 ESCAPE 键时会打开一个弹出窗口。一旦运行,应用程序就会闪烁,然后显示弹出窗口。

    //Pop-up window
Stage window = new Stage();
window.initModality(Modality.NONE);
//Exit Panel
VBox exitBox = new VBox();
exitBox.setPadding(new Insets(10));
Button exitPaneExit = new Button();
exitPaneExit.setText("Return");
exitPaneExit.setMinSize(75.0, 30.0);
exitPaneExit.setOnAction(e -> {
window.close();
});
Button exitButton = new Button();
exitButton.setText("Exit");
exitButton.setMinSize(75.0, 30.0);
exitButton.setOnAction(e -> {
System.exit(0);
});
exitBox.getChildren().addAll(exitPaneExit,exitButton);
exitBox.setVisible(true);
Scene scene = new Scene(exitBox);
window.initStyle(StageStyle.UNDECORATED);
window.initOwner(primaryStage);
window.setScene(scene);
mapScene.setOnKeyPressed(e -> {
if(e.getCode()==KeyCode.ESCAPE)
{
window.show();
}
});

代码运行良好,我没有收到任何错误,但是应用程序在打开弹出窗口时闪烁,这非常烦人。

最佳答案

为什么需要创建另一个舞台?不能使用像这样的简单自定义对话框吗?

Dialog window = new Dialog();
window.setTitle("Your title");
window.setHeaderText("Your header");
window.setContentText("Your Content Text")
window(Modality.APPLICATION_MODAL);
window(mainStage);
window(StageStyle.UTILITY);
ButtonType btnReturn = new ButtonType("return");
ButtonType btnExit = new ButtonType("exit");
window.getDialogPane().getButtonTypes().addAll(btnReturn, btnExit);
mapScene.setOnKeyPressed(e -> {
if(e.getCode()==KeyCode.ESCAPE){
Optional<ButtonType> result = window.showAndWait();
if (result.get() == btnExit){
Platform.exit();
System.exit(0);
}
}
});

我使用 main 方法将阶段从类传递到 Controller ,因此它不应生成任何异常,如下所示:

主类:

public void start(Stage stage) throws Exception {

FXMLLoader loader = new FXMLLoader(getClass().getResource("ToolConfiguration.fxml"));

Parent root = (Parent)loader.load();

ToolConfigurationController controller = loader.<ToolConfigurationController>getController();
controller.setLanguage("en", stage);

notifier = Notification.Notifier.INSTANCE;
[...]
}

对我来说很好用

在 Controller 类中是这样的:

public void setLanguage(String language, Stage stage){
this.mainStage = stage;
this.language=language;

locale = new Locale(language.toLowerCase(), language);
bundle = ResourceBundle.getBundle("smartDrawerTool.bundles.ToolConfiguration", locale);
}

关于java - 打开弹窗时程序闪烁,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39380956/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com