Perthboy
Perthboy

Reputation: 327

JavaFX detect changes of Stage screen location

Is there a way in JavaFX to detect when the Stage/Window position is changed relative to the screen?

I can detect when resizing the Stage but not when the Stage is relocated.

Upvotes: 1

Views: 2075

Answers (1)

DVarga
DVarga

Reputation: 21799

You can use the xProperty and yProperty of Window.

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

Upvotes: 1

Related Questions