I just switched to java 11 (AdaptOpenJDK) 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.
Any help is appreciated.
Thanks.
You can try this one:
-Dsun.java2d.ddscale=true
EDIT:
As official documentation says, "Setting this flag to true enables hardware-accelerated scaling if the DirectDraw/Direct3D pipeline is in use. DirectDraw/Direct3D hardware scaling is disabled by default to avoid rendering artifacts in existing applications"
For more informations you can seee the official Oracle documentation about system properties.