2

So i'm working on this java swing application that is currently running on Java 8 update 192.

It works fine on this update but when I upgrade the java version to 8 update 211, it seems to change the UI of the application so everything seems so much bigger, no code changes are done after switching these versions.

Does anyone know any good resolutions to this issue?

Both images are to the same relative scale, so the after image is much bigger with lower res icons.

Before:

enter image description here

After: enter image description here

M. Deinum
  • 115,695
  • 22
  • 220
  • 224
ZaneK
  • 301
  • 2
  • 14
  • 3
    Is it possibly a DPI related issue? – MadProgrammer Sep 15 '22 at 02:24
  • @MadProgrammer Yes it is, but when adding "-Dsun.java2d.dpiaware=true" to a JAVA_OPTIONS environment variable, to revert it to the old style. I wasn't able to get the changes I wanted after rerunning eclipse, I feel I'm missing something somewhere – ZaneK Sep 15 '22 at 17:30

1 Answers1

3

https://www.oracle.com/java/technologies/javase/8u211-relnotes.html

You can see:

High DPI Auto-Scaling on Windows

If the Windows desktop DPI of the default screen is configured via Display Settings to be 150% or greater (that is 144 dpi or greater), JDK will now ask Windows to auto-scale the entire UI of a Java application to be consistent with the rest of the Windows desktop UI.

Below that value Java applications will appear at the same size as they did in previous releases.

This threshold is chosen as a trade-off between compatibility and legibility of the UI. At higher DPI settings, without this auto-scaling, the Java UI may be just too small to be read comfortably.

There may be some negative consequences such as

  • Some elements of the UI may appear somewhat blurry, particularly if the scaling factor is a non-integral value (that is 1.5 rather than 2.0).

  • ClearType text is not effective when auto-scaling so grey scale anti-aliasing is used instead by the Swing toolkit.

  • Window sizing and positioning calculations may be adversely affected.

In the event that the negative consequences outweigh the benefits, an application can request the old behaviour by specifying:

-Dsun.java2d.dpiaware=true

Conversely, if the application would prefer to be auto-scaled even at lower DPI settings, then specify:

-Dsun.java2d.dpiaware=false

In the absence of either explicit setting, the default behaviour described above will apply.

JDK-8204512 (not public)

core-libs/java.lang

Sully
  • 14,672
  • 5
  • 54
  • 79
  • Yes I think I came across this as well but I was at a loss when I couldn't figure out how to add "-Dsun.java2d.dpiaware=true" anywhere. I tried making the _JAVA_OPTIONS environment variable and added this to that, but when I ran my program in eclipse, it still looked the same – ZaneK Sep 15 '22 at 17:29
  • 1
    @ZaneK, check https://stackoverflow.com/a/862405/643500 you can set it in the `Run Configuration` – Sully Sep 15 '22 at 19:15
  • Oh that's perfect! Would this work if I turn my program into an executable jar file? Do you know if it's possible to maintain my parameters? – ZaneK Sep 15 '22 at 19:55
  • 1
    To run from command line use `java -Dsun.java2d.dpiaware=true -jar application.jar` – Sully Sep 15 '22 at 20:02
  • Any way to do this without the command line? (Just a GUI icon jar)? – ZaneK Sep 15 '22 at 20:03
  • 1
    You can wrap it in `.cmd/.bat` like https://stackoverflow.com/a/8938982/643500 or check https://stackoverflow.com/questions/147181/how-can-i-convert-my-java-program-to-an-exe-file for exe – Sully Sep 15 '22 at 20:22