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

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

这是我的舞台和场景代码

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

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

最佳答案

你需要添加这个:

 newstage.initModality(Modality.APPLICATION_MODAL);
 newstage.showAndWait();

参见 Modality

https://stackoverflow.com/questions/34070334/

相关文章:

c# - wpf - Expander 的标题适合内容宽度?

php - 使用 Prestashop 1.6 在模块中获取产品类别名称

c++11 - 向量的分段平方,C++ Eigen 中两个向量的分段乘积

git - "git clone"是否创建一个完全相对的目录?

scala - 收集和计数操作之间有什么区别?

cordova - react 路由器和 Cordova 不工作

css - 输入内的响应式 fa-icon

php - 编译PHP7错误

c# - 还有其他更好的方法可以将参数传递给 backgroundworker runasync 吗

solr - 使用身份验证在控制台中创建 Solr 核心