How to set the display scale of a Java app from PC

Viewed 28

I'm making an app in Java, and I have a problem with resolution. PCs come with the resolution 1920x1080 and with scale 100%, but laptops come with scale 125% and the app display like shown below. How can I adapt the JFrame according of resolution and scale of each PC?

screen with scale 100%

screen with scale 125%

GraphicsEnvironment env = GraphicsEnvironment.getLocalGraphicsEnvironment();
    GraphicsDevice device = env.getScreenDevices()[0];
    DisplayMode oldMode = device.getDisplayMode();
    DisplayMode newMode = new DisplayMode(1536,864,oldMode.getBitDepth(),oldMode.getRefreshRate());
    device.setDisplayMode(newMode);
Exception in thread "main" java.lang.UnsupportedOperationException: Cannot change display mode
    at java.desktop/java.awt.GraphicsDevice.setDisplayMode(GraphicsDevice.java:432)
    at java.desktop/sun.awt.Win32GraphicsDevice.setDisplayMode(Win32GraphicsDevice.java:452)
0 Answers
Related