当新阶段弹出时,我如何禁用初级阶段

Loo*_*ong 2 java javafx fxml scenebuilder javafx-8

我有按钮会弹出新阶段,但初级阶段不会禁用它仍然可以点击所以如何禁用初级阶段。

这是我的舞台和场景代码

private static final Stage stage = new Stage();
    private static final Stage newstage = new Stage();
    /**
     *
     */

    @Override
    public void start(Stage primaryStage) throws Exception {
      Parent root = FXMLLoader.load(getClass().getResource("MainMenu.fxml"));
      Scene scene = new Scene(root);
      scene.getStylesheets().addAll(this.getClass().getResource("background.css").toExternalForm());
      stage.setScene(scene);
      stage.show();
    }

     public void chgScene (String str) throws Exception {
       Parent root = FXMLLoader.load(getClass().getResource(str));
       Scene scene = new Scene(root);
       stage.setScene(scene);
       stage.show();
    }

    public void addStage (String str) throws Exception {
       Parent root = FXMLLoader.load(getClass().getResource(str));
       Scene scene = new Scene(root);
       newstage.setScene(scene);
       newstage.setResizable(false);
       newstage.showAndWait();
    }

    public void clearStage () {
        newstage.close();
    }
Run Code Online (Sandbox Code Playgroud)

如果有任何错误,很抱歉,因为我是 Java 新手,我需要为我的项目创建一个 GUI。谢谢你的帮助。

Kac*_*hna 6

你需要添加这个:

 newstage.initModality(Modality.APPLICATION_MODAL);
 newstage.showAndWait();
Run Code Online (Sandbox Code Playgroud)

模态