11

There was no proper HiDPI support in Java 8.

In Java 9, JavaFx applications correctly scale to the monitor they are in. For example, if my monitor is set to scale at 150%, the Java application is scaled to 150%.

See: http://openjdk.java.net/jeps/263

However, for testing purposes, I need to be able to disable scaling by using java.exe flags, in Windows 10. How can I achieve this?

Also, maybe I can disable (and re-enable) this programmatically within the application itself?

Marcelo Glasberg
  • 29,013
  • 23
  • 109
  • 133
  • Do you not find any similar configuration on Windows as mentioned in [this answer?](https://superuser.com/a/1207925/528671) – Naman Dec 03 '17 at 02:23
  • @nullpointer Sure, but I need to do it through java.exe flags, not through a configuration on Windows. – Marcelo Glasberg Dec 03 '17 at 02:45
  • 2
    Possible duplicate of [JFrame scaling in Java 9](https://stackoverflow.com/questions/48622712/jframe-scaling-in-java-9) – Adam Feb 05 '18 at 15:00

3 Answers3

13

I found this obscure option in a substance bug report. This fixes the issue for Swing applications.

-Dsun.java2d.uiScale=1.0

If you're using JavaFX you'll need

-Dprism.allowhidpi=false

Unfortunately I cannot find official documentation for either of these options

Adam
  • 35,919
  • 9
  • 100
  • 137
  • 3
    `System.setProperty("sun.java2d.uiScale", "1.0");` worked for me with JDK 11 and Swing, thanks! – mihca Jul 31 '19 at 09:00
4

if needed, found another couple of helpful JVM parameters from that website :

-Dsun.java2d.uiScale.enabled=false
-Dsun.java2d.win.uiScaleX=1.0 -Dsun.java2d.win.uiScaleY=1.0
Jeremie
  • 1,267
  • 12
  • 33
2

Use

System.setProperty( "sun.java2d.uiScale", "1.0" );

in your java code, that worked for me (JDK 17).

cyborck
  • 21
  • 2
  • 1
    Your answer could be improved with additional supporting information. Please [edit] to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Nov 12 '21 at 16:22
  • Does not work for me on Windows 7 and JRE 9.0.4 for some reason – Alex Popov Dec 17 '22 at 18:06