I just switched to Java 11 (AdoptOpenJDK) so that my Java Swing application looks OK on high DPI displays at different system scaling settings.
It works OK on Windows. Regardless of the scaling value configured on the system, Java automatically detects it and uses it to scale the GUI accordingly.
However, on Linux the GUI does not consider the system scaling, and thus, it looks tiny on high-DPI displays.
After reading some posts here, I found I can indicate Java what scaling value to use. For example, if system scaling is 200%, then I can add the following command line argument to the java command used to launch the application.
-Dsun.java2d.uiScale=2.0
The GUI looks fine on Linux when I add the above command line option.
I also read I can set the GDK_SCALE environment variable.
However, I'd like to find a better solution. Ideally, one where I don't need to specify the scaling value to use. Does anybody know if this is possible?
If the above is not possible, then I guess my next step will be to come up with a command in Linux that returns what the current system scaling value is and use it to set the sun.java2d.uiScale
option.
Outside of a set of pre made scales and math scaling for all gui components, you could use borderlayout to size components and gridbaglayout to position components then only fonts and images require math resize.
graphicsdevice and graphicsenvironment classes Re: java.awt.GraphicsConfiguration. getBounds()
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With