我想从我的控制器类处理阶段事件(即隐藏).所以我要做的就是通过添加一个监听器
((Stage)myPane.getScene().getWindow()).setOn*whatIwant*(...);
Run Code Online (Sandbox Code Playgroud)
但问题是初始化刚刚开始
Parent root = FXMLLoader.load(getClass().getResource("MyGui.fxml"));
Run Code Online (Sandbox Code Playgroud)
之前
Scene scene = new Scene(root);
stage.setScene(scene);
Run Code Online (Sandbox Code Playgroud)
因此.getScene()返回null.
我自己找到的唯一解决方法是向myPane.sceneProperty()添加一个监听器,当它变为非null时,我得到场景,添加到它的.windowProperty()我的!该死!我最终检索阶段的监听器处理.这一切都以设置所需的听众来举办舞台活动而告终.我认为听众太多了.这是解决我问题的唯一方法吗?