30

I'm trying to run a Java application with -Dsun.java2d.dpiaware=false argument but nothing happens.

I expect to have a blurred UI but with normal size of icons and fonts, it seems that this flag does not work.

I'm using JDK 1.8.0_45 on Windows 8.1.

I found this bug https://bugs.openjdk.java.net/browse/JDK-8080153 but I don't understand how to workaround it.

blow
  • 12,811
  • 24
  • 75
  • 112
  • Since the dpi-awareness seems to be triggered by an attribute of the launcher, using a different program to launch the JVM might help. – Holger Jun 01 '15 at 16:38
  • 3
    Windows 10 has compatibility settings for the java executables, it's worked perfectly. See the response in this linke `https://superuser.com/questions/988379/how-do-i-run-java-apps-upscaled-on-a-high-dpi-display` – Edward Comeau May 17 '18 at 13:53

3 Answers3

45

Fix for Windows, follow these steps:

  • Create a windows regedit new DWORD

    1. Press Windows Button + R, type “regedit”, and then click OK.
    2. Navigate to the following registry subkey:
      HKEY_LOCAL_MACHINE > SOFTWARE > Microsoft > Windows > CurrentVersion > SideBySide
    3. Right-click, select NEW > DWORD (32 bit) Value
    4. Type PreferExternalManifest, and then press ENTER.
    5. Right-click PreferExternalManifest, and then click Modify.
    6. Enter Value Data 1 and select Decimal.
    7. Click OK.
  • Create the two .manifest file (JDK)

    1. Go to your java JDK installation folder and open the bin directory
    2. Create a first file called java.exe.manifest (add the code at the end of this post).
    3. Create a second one called javaw.exe.manifest (add the code at the end of this post).
  • Create the two .manifest file (JRE)

    1. Go to your java JRE installation folder and open the bin directory
    2. Create a first file called java.exe.manifest (add the code at the end of this post).
    3. Create a second one called javaw.exe.manifest (add the code at the end of this post).
  • Restart your java application.

Code to Paste into the .manifest files

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>

<assembly xmlns="urn:schemas-microsoft-com:asm.v1" manifestVersion="1.0" xmlns:asmv3="urn:schemas-microsoft-com:asm.v3">

<dependency>
  <dependentAssembly>
    <assemblyIdentity
      type="win32"
      name="Microsoft.Windows.Common-Controls"
      version="6.0.0.0" processorArchitecture="*"
      publicKeyToken="6595b64144ccf1df"
      language="*">
    </assemblyIdentity>
  </dependentAssembly>
</dependency>

<dependency>
  <dependentAssembly>
    <assemblyIdentity
      type="win32"
      name="Microsoft.VC90.CRT"
      version="9.0.21022.8"
      processorArchitecture="amd64"
      publicKeyToken="1fc8b3b9a1e18e3b">
    </assemblyIdentity>
  </dependentAssembly>
</dependency>

<trustInfo xmlns="urn:schemas-microsoft-com:asm.v3">
  <security>
    <requestedPrivileges>
      <requestedExecutionLevel
        level="asInvoker"
        uiAccess="false"/>
    </requestedPrivileges>
  </security>
</trustInfo>

<asmv3:application>
  <asmv3:windowsSettings xmlns="http://schemas.microsoft.com/SMI/2005/WindowsSettings">
    <ms_windowsSettings:dpiAware xmlns:ms_windowsSettings="http://schemas.microsoft.com/SMI/2005/WindowsSettings">false</ms_windowsSettings:dpiAware>
  </asmv3:windowsSettings>
</asmv3:application>

</assembly>

This fix can be used for any program, not only Java.

If you need to fix the DPI for a JNLP application launcher, you have to add the following key to the resources section inside the .jnlp file :

<property name="sun.java2d.dpiaware" value="false"/>

After Upgrading Windows (e.g from win10 to win10 1607), you should apply this fix again if it doesn't work anymore.

** Afer Updating Java, you should copy&paste .manifest files into new Java's directory.

t0re199
  • 730
  • 2
  • 9
  • 14
  • 2
    Wish I could upvote you more than once. Worked for me! – adamsuskin Sep 16 '16 at 20:09
  • 1
    not gonna downgrade it but it didn't work for me, the problem is that only 3 people have tried this fix for the moment. I'm using windows 10 on 64, tried to run a java program from eclips and still a minature windows – Flying Turtle Dec 18 '16 at 01:03
  • 2
    @FlyingTurtle i can tell you that this fix works fine with eclipse too. Make sure to copy .manifest files into jdk and jre you re using. Maybe you' ve installed more java versions and the eclipse project that you re working on is using a version in which .manifest files has not been created. – t0re199 Dec 19 '16 at 06:17
  • @t0re199 I'm sorry, I did not follow your directions correctly, I had not copied the .manifest files in the jre bin only the jdk. having rectified this it now works properly, good job on a great fix. thank you. – Flying Turtle Dec 20 '16 at 05:46
  • @t0re199 one last note, oddly enough when I run it from eclips it works fine but if I run th same program from cmd it shows up small again... – Flying Turtle Dec 22 '16 at 02:20
  • @FlyingTurtle yes, i knew my fix didn't work while launching java programs via cmd, i was looking for a fix to update my answare. Now i can give you a fix for cmd too, this fix is a java program which i developed for personal use but i think it's now stable enough to be shared. I called it JavaWin4kCmdRunner, it will run your java program via cmd scaled in the right way. PS: i coludn't fix cmd with .manifest files, i think it has something to do with windows environment variables. Here's JavaWin4kCmdRunner source code link: pastebin.com/A5XtM4b1 – t0re199 Dec 29 '16 at 13:33
  • @DZD have you recreated the .manifest files in the new java's folder? (Check both jre and jdk). I got it working on the latest java update. If you read my answare more accurately, the last 3 lines tell you " After Updating Java, you should copy&paste .manifest files into java's new directory. Again check both jre and jdk. Have a nice day. – t0re199 Jan 24 '17 at 07:50
  • To add to your answer (which is great, as it pointed me where to look), if you need to fix the DPI for a JNLP application launcher, you have to add the following key to the resources section inside the .jnlp file : Thanks ;) – Bruce Feb 02 '17 at 02:23
  • @Bruce i've just added it. – t0re199 Feb 04 '17 at 07:22
  • @KrzysztofCichocki have you recreated the .manifest files in the new java's folder? (Check both jre and jdk). I got it working on the latest java update. If you read my answare more accurately, the last 3 lines tell you " After Updating Java, you should copy&paste .manifest files into java's new directory. Again check both jre and jdk. If you have updated Windows,as i stated in the answare, you ll have to reapply the fix even in regedit. Guys please, read the answare more carefully. Have a nice day. – t0re199 Feb 14 '17 at 11:38
  • yes, I have these manifests in all java installation directories on this machine, also the registry entry is fresh new and checked five times. – Krzysztof Cichocki Feb 16 '17 at 13:36
  • @KrzysztofCichocki What java version are you using? How Are you running your application? – t0re199 Feb 16 '17 at 18:57
  • java version "1.8.0_111" Java(TM) SE Runtime Environment (build 1.8.0_111-b14) Java HotSpot(TM) 64-Bit Server VM (build 25.111-b14, mixed mode) – Krzysztof Cichocki Feb 17 '17 at 12:38
  • @KrzysztofCichocki just tested, i got it working on that jre version. If you manage to figure out why it doesn t work for you, please let me know and i ll update the answare. Have a nice day. – t0re199 Feb 19 '17 at 21:00
  • 4
    To all people who are struggling to make this fix work: In my case the java and javaw executables which were used by the Java applet weren't the ones in the default Java install folder (either JDK or JRE). So an easy way to find out if you've put the .manifest files in the correct folder is: 1) Start you java applet 2) Open task manager 3) Find "Java(TM) Platform SE binary" (or something similar) 4) Right click and select "Open location.." 5) Copy java.exe.manifest and javaw.exe.manifest to the folder you've just opened – William Lekatompessy Mar 08 '17 at 14:46
  • How do you figure out things like these? – ave4496 Nov 29 '17 at 14:10
  • @user489872 i could try to explain but i think that 600 chars couldn't be enough for that, i'm sorry. – t0re199 Nov 30 '17 at 18:46
  • 1
    I had this problem with JabRef on WIndows 10 (and netbeans too), which seems to directly create a java vm. I made a JabRef.exe.manifest as described in this answer and voila, fixed. Thanks! – Bull May 19 '18 at 14:35
  • @Bull Glad to hear that! This fix can be used for almost any program. – t0re199 May 21 '18 at 07:42
  • If you have spent all day trying to get your Java app to behave (in my case its Cisco ASDM), and you know your Java JRE or JDK is in ```C:\Program Files\Java\jre1.8.0_191\bin```, that does not mean your Java app actually runs from there. As indicated by others, right click on your running Java application in task manager and use Open Location to find where your manifest files must go. In my case it was in ```C:\Program Files (x86)\Common Files\Oracle\Java\javapath_target_546453```, not in directory I installed JRE to. – Lukasz Nov 03 '18 at 19:21
  • @t0re 199 I upvoted your answer. If you can I would recommend you edit your answer to include comment about finding correct Java binaries by using Task Manager while application is running! – Lukasz Nov 03 '18 at 19:23
  • 1
    My java application have embedded jre directory and I created two manifest file according to the above instruction and paste those two manifest file in to the jre directory. Then I create new registry key. It's not worked for me. My application is 32 bit running on 64 bit windows version. any issue? – Pubudu Mahesh Meththananda Aug 19 '19 at 08:30
9

try running the vm with -Dsun.java2d.uiScale=1, it fixed my swing/vtk app

sherpya
  • 4,890
  • 2
  • 34
  • 50
  • 2
    This fixed a problem I was having with windows and fonts scaling up on a 1920x1080 display after upgrading from JDK 8 to JDK 11, so I thank you for that, even though it's probably not relevant to the original question, which was concerning specifically JDK 8. – Kevin Rahe Sep 20 '19 at 16:19
  • 1
    you are right, but I've stumbled here while fixing same problem, I've added this in the home someone can benefit – sherpya Sep 21 '19 at 15:20
  • 1
    This should be the accepted answer. Works like a charm. Never hava I seend such a bloated application on my 4K monitor with 150% scaling. – Avec Nov 13 '19 at 10:09
0

you can simply use :

System.setProperty("prism.allowhidpi", "false");

It is important that this is at the very start of your application before your main arguments get initialized, i.e. before Application.launch() or at the begining of your main() function

majed
  • 467
  • 4
  • 7