Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

obtain Windows 10 Display settings values in Java

Tags:

java

When user change Display settings scaling (Windows 10, right click on desktop, select Display settings and scale to 150%), suddenly all values reported by

GraphicsDevice device = MouseInfo.getPointerInfo().getDevice();
    Rectangle bounds = device.getDefaultConfiguration().getBounds();

or

Toolkit.getDefaultToolkit().getScreenSize();

or

GraphicsEnvironment.getLocalGraphicsEnvironment().getMaximumWindowBounds();

become invalid. Is there a way how to get the actual values ?

like image 803
Lukas Hanacek Avatar asked Oct 30 '22 16:10

Lukas Hanacek


1 Answers

Found solution that seems to respect the Display settings.

javafx.geometry.Rectangle2D r = new javafx.geometry.Rectangle2D(0, 0, 1, 1);
ObservableList<Screen> screens = Screen.getScreensForRectangle(r);
if (screens != null && screens.size() > 0) {
    javafx.geometry.Rectangle2D rc = screens.get(0).getBounds();
}
like image 77
Lukas Hanacek Avatar answered Nov 09 '22 13:11

Lukas Hanacek