Java禁用dpi-aware不起作用

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/30555401/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-11 09:48:41  来源:igfitidea点击:

Java disable dpi-aware not working

javajava-8jvm-argumentsdpi-aware

提问by blow

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

我正在尝试使用-Dsun.java2d.dpiaware=false参数运行 Java 应用程序,但没有任何反应。

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.

我在 Windows 8.1 上使用 JDK 1.8.0_45。

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

我发现这个错误https://bugs.openjdk.java.net/browse/JDK-8080153但我不明白如何解决它。

采纳答案by t0re199

Fix for Windows, follow these steps:

修复 Windows,请按照下列步骤操作:

  • 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.

  • 创建一个 windows regedit 新的 DWORD

    1. 按 Windows 按钮 + R,键入“regedit”,然后单击“确定”。
    2. 导航到以下注册表子项:
      HKEY_LOCAL_MACHINE > SOFTWARE > Microsoft > Windows > CurrentVersion > SideBySide
    3. 右键单击,选择 NEW > DWORD(32 位)值
    4. 键入 PreferExternalManifest,然后按 Enter。
    5. 右键单击 PreferExternalManifest,然后单击修改。
    6. 输入数值数据 1 并选择十进制。
    7. 单击确定。
  • 创建两个 .manifest 文件(JDK

    1. 转到您的java JDK安装文件夹并打开bin目录
    2. 创建一个名为 java.exe.manifest 的第一个文件(在本文末尾添加代码)。
    3. 创建另一个名为 javaw.exe.manifest 的文件(在本文末尾添加代码)。
  • 创建两个 .manifest 文件 ( JRE)

    1. 转到您的 java JRE 安装文件夹并打开 bin 目录
    2. 创建一个名为 java.exe.manifest 的第一个文件(在本文末尾添加代码)。
    3. 创建另一个名为 javaw.exe.manifest 的文件(在本文末尾添加代码)。
  • 重新启动您的 Java 应用程序。

Code to Paste into the .manifest files

粘贴到 .manifest 文件中的代码

<?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.

此修复程序可用于任何程序,而不仅仅是 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 :

如果您需要修复 JNLP 应用程序启动器的 DPI,您必须将以下键添加到 .jnlp 文件内的资源部分:

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

<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.

升级 Windows 后(例如从 win10 到 win10 1607),如果它不再起作用,您应该再次应用此修复程序。

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

** 在更新 Java 之后,您应该将 .manifest 文件复制并粘贴到新的 Java 目录中。

回答by sherpya

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

尝试使用 运行 vm -Dsun.java2d.uiScale=1,它修复了我的 Swing/vtk 应用程序