JavaFX 检测舞台屏幕位置的变化
JavaFX detect changes of Stage screen location
JavaFX 中有没有一种方法可以检测 Stage/Window 位置相对于屏幕的变化?
我可以检测到何时调整舞台大小时,但不能检测到何时重新定位舞台。
您可以使用 Window
的 xProperty
and yProperty
。
The horizontal location of this Stage on the screen. Changing this
attribute will move the Stage horizontally. Changing this attribute
will not visually affect a Stage while fullScreen is true, but will be
honored by the Stage once fullScreen becomes false.
stage.xProperty().addListener((obs, oldVal, newVal) -> System.out.println("X: " + newVal));
stage.yProperty().addListener((obs, oldVal, newVal) -> System.out.println("Y: " + newVal));
JavaFX 中有没有一种方法可以检测 Stage/Window 位置相对于屏幕的变化?
我可以检测到何时调整舞台大小时,但不能检测到何时重新定位舞台。
您可以使用 Window
的 xProperty
and yProperty
。
The horizontal location of this Stage on the screen. Changing this attribute will move the Stage horizontally. Changing this attribute will not visually affect a Stage while fullScreen is true, but will be honored by the Stage once fullScreen becomes false.
stage.xProperty().addListener((obs, oldVal, newVal) -> System.out.println("X: " + newVal));
stage.yProperty().addListener((obs, oldVal, newVal) -> System.out.println("Y: " + newVal));