2

I am running Windows 10 64 bit and have JDKs and JRE 8 (1.8.0_152) and 9(9.0.1) installed.

I have a GUI (Swing) that I am working on in IntelliJ IDEA Community 2017.2. I have setup Icon and Font sizes to my liking and the program runs and looks when it is run inside IntelliJ. I have created an Artifact (JAR) and everything shows correctly IF it is run inside IntelliJ. However, IF I run (double-click) the JAR file outside IntelliJ, all icons and text are bigger/scaled up and they look blurry. I have IntelliJ run all projects with 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.

I have also looked at using launch4j because if the JAR is wrapped it might not suffer from DPI scaling, is this correct?

What can I do to run my JAR file and that it looks exactly as it looks inside IntelliJ?

Thank you very much!

P.S.: This is the program when run inside IntelliJ enter image description here

This is the program when running (double clicking) the JAR enter image description here

  • Did you try running it on JetBrains Runtime? See https://intellij-support.jetbrains.com/hc/articles/206544879. – CrazyCoder Feb 06 '18 at 19:57
  • @CrazyCoder According to the link you provided, "...JDK (JetBrains Runtime) is bundled with all the product installers and it's recommended that you will use the provided JDK version unless there are any specific issues. Since 2017.1 version 64-bit JDK is bundled by default on all the systems..." This is the About info I have: IntelliJ IDEA 2017.2.6 Build #IC-172.4574.11, built on November 13, 2017 JRE: 1.8.0_152-release-915-b12 amd64 JVM: OpenJDK 64-Bit Server VM by JetBrains s.r.o Windows 10 10.0 – Alejandro Martinez Feb 07 '18 at 10:55
  • I mean run your app with this runtime, not IntelliJ IDEA. – CrazyCoder Feb 07 '18 at 10:56
  • @CrazyCoder Any pointers on how to do that? Thanks – Alejandro Martinez Feb 07 '18 at 10:57
  • Download the runtime from https://bintray.com/jetbrains/intellij-jdk/ and use it to run your app instead of the Oracle java. – CrazyCoder Feb 07 '18 at 10:58
  • @CrazyCoder I did what you suggested, however, results are the same :-( Thanks for your help! – Alejandro Martinez Feb 07 '18 at 11:44

1 Answers1

1

I have solved the problem!

I found this post here:

How to set the DPI of Java Swing apps on Windows/Linux?

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:

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.

The second answer tells to run the app using JRE 9!!! and explains that it supports DPI scaling for Swing and AWT.

So... I set up IntelliJ to use JDK 9 and... Ugly icons and scaled-up text showed up in the app running inside 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!!! (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).

I ran my JAR file explicitly using JRE 1.8 like this:

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!