简体   繁体   English

图标和文本在 IntelliJ IDE 中看起来不错,但在运行 JAR 文件时它们看起来模糊/放大

[英]Icons and text look OK in IntelliJ IDE, but they look blurry/scaled up when running the JAR file

I am running Windows 10 64 bit and have JDKs and JRE 8 (1.8.0_152) and 9(9.0.1) installed.我正在运行 Windows 10 64 位并安装了 JDK 和 JRE 8 (1.8.0_152) 和 9(9.0.1)。

I have a GUI (Swing) that I am working on in IntelliJ IDEA Community 2017.2.我在 IntelliJ IDEA Community 2017.2 中有一个 GUI(Swing)。 I have setup Icon and Font sizes to my liking and the program runs and looks when it is run inside IntelliJ.我已经根据自己的喜好设置了图标和字体大小,并且程序在 IntelliJ 中运行时会运行并看起来。 I have created an Artifact (JAR) and everything shows correctly IF it is run inside IntelliJ.我创建了一个 Artifact (JAR),如果它在 IntelliJ 中运行,一切都会正确显示。 However, IF I run (double-click) the JAR file outside IntelliJ, all icons and text are bigger/scaled up and they look blurry.但是,如果我在 IntelliJ 之外运行(双击)JAR 文件,所有图标和文本都会变大/放大,并且看起来很模糊。 I have IntelliJ run all projects with 1.8.我让 IntelliJ 使用 1.8 运行所有项目。

I have read about Java/Swing DPI scaling (apparently Swing reports that it can do scaling or something like that and in turn Windows tries to scale up the program) but I do not fully understand what that is and what is going on.我已经阅读了有关 Java/Swing DPI 缩放的内容(显然 Swing 报告说它可以进行缩放或类似的操作,而 Windows 会尝试缩放该程序),但我不完全了解那是什么以及正在发生什么。

I have also looked at using launch4j because if the JAR is wrapped it might not suffer from DPI scaling, is this correct?我还考虑过使用 launch4j,因为如果 JAR 被包装,它可能不会受到 DPI 缩放的影响,这是正确的吗?

What can I do to run my JAR file and that it looks exactly as it looks inside IntelliJ?我该怎么做才能运行我的 JAR 文件并且它看起来与 IntelliJ 中的完全一样?

Thank you very much!非常感谢!

PS: This is the program when run inside IntelliJ PS:这是在IntelliJ中运行时的程序在此处输入图片说明

This is the program when running (double clicking) the JAR这是运行(双击)JAR 时的程序在此处输入图片说明

I have solved the problem!我已经解决了问题!

I found this post here:我在这里找到了这篇文章:

How to set the DPI of Java Swing apps on Windows/Linux? 如何在 Windows/Linux 上设置 Java Swing 应用程序的 DPI?

Even though, the OP had a different problem (the fonts on his Java Swing app are too small and the app DOES NOT scale up automatically) the following two answers helped me find the solution:尽管如此,OP 有一个不同的问题(他的 Java Swing 应用程序上的字体太小,应用程序不会自动扩展)以下两个答案帮助我找到了解决方案:

The first answer shows some research on the Swing LAF (Look And Feel) and that only JavaFX supports DPI scaling to 150% on this person's system.第一个答案显示了对 Swing LAF(外观和感觉)的一些研究,并且只有 JavaFX 支持在此人的系统上将 DPI 缩放到 150%。

The second answer tells to run the app using JRE 9!!!第二个答案告诉使用JRE 9运行应用程序!!! and explains that it supports DPI scaling for Swing and AWT.并解释说它支持 Swing 和 AWT 的 DPI 缩放。

So... I set up IntelliJ to use JDK 9 and... Ugly icons and scaled-up text showed up in the app running inside IntelliJ!!!所以......我设置了 IntelliJ 以使用 JDK 9 和......丑陋的图标和放大的文本出现在 IntelliJ 内部运行的应用程序中!!!

Then it hit me!然后它击中了我!

I have both JRE 8 AND JRE 9 (and also JDK 1.8 & JDK 9) installed in my system... Of course my system is using the latest one!!!我的系统中安装了 JRE 8 和 JRE 9(以及 JDK 1.8 和 JDK 9)...当然我的系统使用的是最新的!!! (I was just to blind to see that, actually it never crossed my mind to think about this) (我只是看到那个,实际上我从来没有想过这个问题)

Basically, I was developing in IntelliJ using JDK 1.8 and then running the JAR file using the default JRE on my system (JRE 9 which has DPI scaling capabilities for Swing applications).基本上,我使用 JDK 1.8 在 IntelliJ 中进行开发,然后使用系统上的默认 JRE(JRE 9,它具有用于 Swing 应用程序的 DPI 缩放功能)运行 JAR 文件。

I ran my JAR file explicitly using JRE 1.8 like this:我使用 JRE 1.8 显式运行我的 JAR 文件,如下所示:

c:\path-to-jar>"path-to-my-jre1.8.0_151-javaw.exe" -jar MyJAR.jar

And... icons and text showed up correctly!而且...图标和文字正确显示!

Hope this helps someone!希望这可以帮助某人!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM