Java / Swing how to deal with different screen DPI and density settings?

前端 未结 3 1960
广开言路
广开言路 2021-02-10 10:35

Hi everyone I\'ve recently come across the problem that now days some monitors have different DPI settings, some monitors are much more dense such as, for example, Apple\'s Reti

3条回答
  •  终归单人心
    2021-02-10 10:52

    Use JRE 9 (or greater).

    This is because the Java runtime (older versions) declared themselves 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.

    Then, You need to run it on JRE 9 because it really supports this feature.

提交回复
热议问题