程序在弹出窗口打开时闪烁

时间:2016-09-08 00:42:10

标签: java javafx

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

$typography-list: h1, h2......
@mixin tg($font-size,$line-height) {
  something related to font-size and line-height
}


@each $typography in $typography-list {
  create @mixin {
    @include tg()
  }
}

代码运行良好,我没有错误,但应用程序在打开弹出时闪烁,这很烦人。

2 个答案:

答案 0 :(得分:1)

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

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方法的类从舞台传递给控制器​​,因此它不应该生成任何异常,如下所示:

主要课程:

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;
    [...]
}

它适用于我

在控制器类中出现如下:

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);
}

答案 1 :(得分:0)

我终于通过Popup类的实现找到了解决方案。这种效果与使用initOwner创建透明/实用程序阶段相同,但内置于JavaFX中。如果显示它需要一个initOwner,这就是我放在那里的参数。

以下是代码:

与实际弹出窗口相关的代码。

    private Popup addExitPopup(){
    Popup exitPopup = new Popup();
    //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 -> {
        exitPopup.hide();
    });
    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);

    exitPopup.setAutoHide(true);
    exitPopup.getContent().add(exitBox);
    return exitPopup;
}

与使其显示在全屏应用程序中相关的代码。

    @Override
public void start(Stage primaryStage) throws Exception {
    Popup exitPopupO = addExitPopup();
    AnchorPane mapAnchorO = addMapAnchor();
    Scene mapScene = new Scene(mapAnchorO);
    primaryStage.setScene(mapScene);
    primaryStage.setFullScreen(true);
    primaryStage.setResizable(false);
    primaryStage.setFullScreenExitKeyCombination(KeyCombination.NO_MATCH);
    primaryStage.show();

    mapScene.setOnKeyPressed(e -> {
        if(e.getCode()==KeyCode.ESCAPE)
        {
            exitPopupO.show(primaryStage);
        }
    });
}