我将此控制器与FXML相关联:
public class MainController {
private Stage stage;
@FXML
private BorderPane mainPane;
@FXML
public void initialize() {
}
private Stage getStage() {
stage = (Stage) mainPane.getScene().getWindow();
return stage;
}
}
我需要拦截窗口调整大小事件。
我该如何在控制器中执行此操作?
答案 0 :(得分:0)
@FXML
public void initialize() {
mainPane.sceneProperty().addListener((observableScene, oldScene, newScene) -> {
if (oldScene == null && newScene != null) {
newScene.windowProperty().addListener((observableWindow, oldWindow, newWindow) -> {
if (oldWindow == null && newWindow != null) {
getStage().widthProperty().addListener((obs, oldVal, newVal) -> {
System.out.println(newVal);
});
}
});
}
});
}
private Stage getStage() {
stage = (Stage) mainPane.getScene().getWindow();
return stage;
}
实际上,检查场景是否已经设置。 谢谢再见!