I'm trying to run a Java app (JAR file) on a high-DPI display on Windows 10. The app uses Swing and thus isn't DPI-aware. Normally when I run an application that isn't DPI-aware, Windows will scale it for me, albeit blurry. But for some reason it's not scaling the Java app; I just get a tiny little window in the corner with impossible-to-read text. How do I run a Java app with Windows' high-DPI (blurry) scaling?

  • Is it your application and do you control the sources/objects, or is it a legacy application that is now unchangeable ? – harrymc Nov 20 '15 at 14:57
  • 2
    It's not my application; no control over the source. – Jeff E Nov 20 '15 at 18:53
  • Bad news, you might need to lower your DPI to run that application. Here are some resources with hacks that might help : Fix blurry fonts in Windows 10, DPI Settings in Windows 10, Windows 10 DPI blurry. Create at least a system restore point backup before trying them out, just in case. The fallback solution might be to return to Windows 7. – harrymc Nov 20 '15 at 19:39
  • 3
    @harrymc How would either of the above help? The problem isn't blurry fonts or that it refuses to run, the problem is that everything is tiny. The "blurry" font rendering is what I want to achieve, and as I understood the OP's question, they do too. Setting the DPI scaling to 100% would make the whole system tiny; setting the display resolution to a non-native one would make everything look blurry. (Okay, no blurrier than on a 1080p display for me, but still.) – millimoose Nov 25 '15 at 20:48
  • 1
    @harrymc And while the latter might make the app usable, I'm sure you understand why answering "how do I make X work on a 2160p display?" with "use a worse display" is kind of missing the point. – millimoose Nov 25 '15 at 20:49

10 Answers 10

up vote 30 down vote accepted

The problem here seems to be that Swing is by default claiming that it is DPI aware, so windows doesn't scale it. Use this switch to turn off this behavior and windows will start scaling your swing app:

-Dsun.java2d.dpiaware=false

[EDIT: Unfortunately, this flag no longer seems to work in Java 8, I was testing it in Java 6. Looks like this is a known issue.]

[EDIT 2: You can modify a Java 8 install to work correctly, using a program to modify the EXE manifests. I changed the setting from true to false in the manifests inside of java.exe and javaw.exe, and now my Swing programs scale correctly in Windows 10 high dpi. I used Resource Tuner to this.]

[Edit 3] Just use Java 9

  • Can you elaborate on the edit #2? Which setting did you modify in the manifest, exactly? – Tomalak Nov 11 '16 at 14:56
  • In the Manifest XML, it is the <dpiAware> flag under <asmv3:application><asmv3:windowsSettings> – CarlG Nov 17 '16 at 17:39
  • That's the point. I've seen that flag and I set it to false, but the application (JNLP/WebStart) did not scale properly either way. Can you think of a simple way to cross-check whether this works or not, e.g. a test app that you know of that responds to this setting? – Tomalak Nov 17 '16 at 17:45
  • Webstart is particularly finicky because it can be hard to pinpoint exactly which executable in which jre distro you have installed you end up using. As a cross-check, I'd try launching your app directly with java.exe or javaw.exe and skipping JWS to see if there's a difference. – CarlG Dec 5 '16 at 14:39
  • 2
    This is somewhere between comical and farcical. The framework mis-reports its capabilities and the switch that fixed the error is removed. The only work-around? For end-users to buy a 3rd party tool. And people wonder why Java has such a poor reputation. – Basic Aug 1 '17 at 12:52

Just found an easy solution on my Windows 10 machine:

  1. Find java.exe you installed.
  2. Right click -> Properties
  3. Go to Compatibility tab
  4. Check Override high DPI scaling behavior.
  5. Choose System for Scaling performed by:
  • 2
    Best solution - I had this problem running a .jnlp file so I had to change the "C:\Program Files\Java\jre1.8.0_131\bin\jp2launcher.exe" but this worked like charm. – Dror Harari May 18 '17 at 13:49
  • For me it was the JDK version. Found by right clicking and opening the options from the task manager in Windows 10. – Brian Knoblauch May 31 '17 at 18:32
  • 3
    For Windows 10, running Java-based Minecraft launchers, I had to change all the installed Java versions on my system for it to work (java.exe and javaw.exe). – cyberbit Jul 10 '17 at 22:32
  • 4
    I used a less intrusive variant. I created a shortcut for command java -jar myJarFile.jar and did the steps 2 to 5 on that shortcut (Windows 10, Java 8). – Julien Kronegg Aug 25 '17 at 11:41
  • 1
    For me, it was javaw.exe – masterxilo Dec 13 '17 at 11:28

Solution: Run it on JRE 9.

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.

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

  • I'll be really excited if Java9 fixes this. – music2myear Aug 1 '17 at 0:12
  • 2
    This fails to point out you have to recompile the code. Simply running the same Java 8- application on Java 9+ won't change the behavior – Ramhound Aug 1 '17 at 1:25
  • Running HiDPI programs on Java 9 solves a lot of problems. goo.gl/3zmL7b – Gernot Krost Sep 23 '17 at 17:45
  • 3
    @Ramhound You don't have to recompile. I just built a jar with JDK8 for Java 8 that overrides a fullscreen JPanel's paint() method on a W10 system with 4K screen and 200% scale setting. Run with the java.exe of Java 8, the Graphics2D object given to the method has a scaling of 1, and the JPanel has a getWidth/height of 3840x2160. Run with the java.exe of Java 9, the scaling is 2 and the width/height is 1920x1080. – Dreamspace President Oct 8 '17 at 6:48
  • @DreamspacePresident Exactly what I thought. This is because JREs are usually backwards compatible, meaning that code built on Java 1.4 will run on Java 5, 6, 7, etc; whereas JDKs are usually forwards compatible, meaning that code compiled for Java 1.5 do not necessarily compile for 1.4 or earliest versions. – Sergio Muriel Oct 9 '17 at 21:45

If you stumbled across this question but are actually looking for a solution that works on Linux, this is for you.

If you can add parameters to the java binary which launches the application, you can use the option -D to pass a value for the sun.java2d.uiScale proprty to specify a scaling factor for Java2D. This will scale your application. The scaling factor value is a double. Make sure that you pass this option to the java binary itself, not the launched Java application.

Example: Launch NearInfinity.jar with a UI scaling factor of 2.5

java -Dsun.java2d.uiScale=2.5 -jar ~/jars/NearInfinity.jar

I found this article quite useful in general for running Linux on HiDPI systems, and some of the things might work on Windows as well: https://wiki.archlinux.org/index.php/HiDPI

  • This is good, though I wish I could get a scaling of 1 for JFrames and the system scaling for JOptionPanes. – NateS Aug 11 at 13:01

You need to set PreferExternalManifest in regedit and create custom manifests for java.exe and javaw.exe as given in following stackoverflow answer https://stackoverflow.com/a/39372897

  • 2
    Good news, the Fall Creators update allows you to change scaling behaviour by right clicking on the item, selecting properties and then the compatibility tab. Creating a custom external manifest is no longer needed - which is nice. – Richard Dec 19 '17 at 16:26

To force all java executables to have "properties > compatibility > dpi scaling mode" set to "System", in an administrator powershell (win-x, a), run:

$javaexes = (Get-ChildItem -path "$env:ProgramFiles\Java","${env:ProgramFiles(x86)}\java" -filter java?.exe -recurse  | Where-Object {$_.Name -match "java(|w).exe"} ).fullname

$javaexes | foreach {REG ADD "HKCU\Software\Microsoft\Windows NT\CurrentVersion\AppCompatFlags\Layers"  /V $_ /T REG_SZ /D "~ DPIUNAWARE" /F}

to undo:

$javaexes | foreach {REG delete "HKCU\Software\Microsoft\Windows NT\CurrentVersion\AppCompatFlags\Layers"  /V $_ /f}

Instead of HKCU you could use HKLM, but then you cannot change the dpi-scaling setting manually anymore in the properties > compatibility dialog of the java*.exe files.

Thanks for Kenneth. I find C:\Program Files (x86)\Java\jre\bin\java.exe then right click -> properties -> compatibility tab -> "override high DPI scaling behavior" and select System, then it works.I also tried the same way to change the javaw.exe's compatibility, it also works.

PS: I run burpsuite.jar on win10 1703 using that method.

Elderry's solution is good, but what if you want to run a jar file on Windows and it doesn't have compatibility options?

Go to C:\Program Files (x86)\Java\jre\bin and find javaw.exe. Right click, properties, compatibility tab, check "override high DPI scaling behavior" and select "System" (Note that "System enhanced" did not work for me).

Now jar file windows should scale properly with readable text. If not, it might mean that Windows doesn't link jar type files to javaw.eve like it should. A third party fix is available at: https://johann.loefflmann.net/en/software/jarfix/index.html

Try Java 10.

I found that -Dsun.java2d.dpiaware=false does not work in Java 9 or 10. Also for Java 8 and 9 my swing app is small, but Java 10 sizes properly in windows!

so for an app that you can run from a bat file like: java -jar xxx.jar

I just added JAVA_HOME=....\java_10 and PATH=%JAVA_HOME%\bin;%PATH% in the bat file.

java -jar xxx.jar

I was able to get sensible dpi when ran using command prompt like:

%SystemRoot%\system32\cmd.exe /C C:\your.file.path\yourJarFile.jar

Your Answer

 

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.