How to set the DPI of Java Swing apps on Windows/Linux?

前端 未结 6 779
鱼传尺愫
鱼传尺愫 2020-11-29 21:14

If you have an monitor with a DPI over 150 (such as Macbook Pro), you may also find the problem: the font on the Java Swing app is too small for high DPI monitor

6条回答
  •  迷失自我
    2020-11-29 22:04

    Short answer: You need to run it on JRE 9+.

    Long answer:
    This is because the Java runtime declared itself to be "DPI-aware" but didn't really supported it for AWT and Swing. Java applications were sized and rendered based on pixels rather than being properly scaled, this included HiDPI displays. Anyways, this has been recently solved. See the issue JEP 263: HiDPI Graphics on Windows and Linux and the upgrade.

    So, increasing the font size does not work (because it does not increase the rest of the things); the jvm argument -Dsun.java2d.dpiaware=false does not work (because it is not really supported); and the manifest file + registry edit (for Windows) just does not work.

    Solution: You need to run it on JRE 9+ because it really supports this feature.

提交回复
热议问题