How to detect screen orientation change? - JavaFX on Microsoft Surface

Viewed 547

I am writing a JavaFX application for Microsoft Surface and I am looking for a way to detect a screen orientation change when rotating the device from portrait to landscape and vice versa. The current method I am using to detect the screen orientation is as follows:

window.widthProperty().addListener((obs, oldVal, newVal) -> {
    if((double) newVal < window.getHeight()) {
        setPortraitMode();
    } else {
        setLandscapeMode();
    }
});

This method works fine for manual window resizing. However, the orientation change (device rotation) does not trigger a window resize event, so the method to change the layout will not fire automatically.

What is the proper way to detect the screen orientation change without listening for resizing event?

1 Answers
Related