如何在javafx中访问控制器中的应用程序
答
您可以在场景的任意节点上调用以下内容来获取当前舞台。
Node.getScene().getWindow()
它会给你一个类型为Window的对象。
FXMLLoader fxmlLoader = new FXMLLoader(getClass().getResource(
"Main.fxml"));
fxmlLoader.setRoot(this);
MainController controller = new MainController()
controller.setStage(stage);
fxmlLoader.setController(controller);
try {
fxmlLoader.load();
} catch (IOException exception) {
throw new RuntimeException(exception);
}
:(第一阶段的子类窗口)
,或者从控制器外部交出阶段