Java disable dpi-aware not working
Asked Answered
B

3

31

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.

Brett answered 31/5, 2015 at 8:31 Comment(2)
Since the dpi-awareness seems to be triggered by an attribute of the launcher, using a different program to launch the JVM might help.Mound
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-displayCalcify
B
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.

Bergstein answered 7/9, 2016 at 14:39 Comment(22)
Wish I could upvote you more than once. Worked for me!Eveleen
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 windowsOsteo
@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.Bergstein
@Bergstein 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.Osteo
@Bergstein 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...Osteo
@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/A5XtM4b1Bergstein
@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.Bergstein
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 : <property name="sun.java2d.dpiaware" value="false"/> Thanks ;)Crustaceous
@Crustaceous i've just added it.Bergstein
@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.Bergstein
yes, I have these manifests in all java installation directories on this machine, also the registry entry is fresh new and checked five times.Dowitcher
@KrzysztofCichocki What java version are you using? How Are you running your application?Bergstein
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)Dowitcher
@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.Bergstein
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 openedJordonjorey
How do you figure out things like these?Blacksmith
@user489872 i could try to explain but i think that 600 chars couldn't be enough for that, i'm sorry.Bergstein
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!Perturbation
@Perturbation Glad to hear that! This fix can be used for almost any program.Bergstein
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.Quotha
@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!Quotha
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?Step
M
9

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

Marmite answered 13/9, 2019 at 15:28 Comment(3)
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.Maniple
you are right, but I've stumbled here while fixing same problem, I've added this in the home someone can benefitMarmite
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.Aeriel
F
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

Floorage answered 27/7, 2020 at 15:27 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.