How do I run Java apps upscaled on a high-DPI display?
Rise to the top 3% as a developer or hire one of them at Toptal: https://topt.al/25cXVn
--------------------------------------------------
Track title: CC L Beethoven - Piano Sonata No 8 in C
--
Chapters
00:00 How Do I Run Java Apps Upscaled On A High-Dpi Display?
00:41 Answer 1 Score 115
01:09 Accepted Answer Score 49
02:09 Answer 3 Score 49
03:15 Answer 4 Score 15
04:13 Answer 5 Score 7
05:02 Thank you
--
Full question
https://superuser.com/questions/988379/h...
--
Content licensed under CC BY-SA
https://meta.stackexchange.com/help/lice...
--
Tags
#windows10 #java #highdpi
#avk47
ANSWER 1
Score 115
Just found an easy solution on my Windows 10 machine:
- Find
java.exe
you installed. - Right click ->
Properties
- Go to
Compatibility
tab - Check
Override high DPI scaling behavior.
- Choose
System
forScaling performed by:
ACCEPTED ANSWER
Score 49
The problem here seems to be that Swing is by default claiming that it is DPI aware, so windows doesn't scale it. Use this switch to turn off this behavior and windows will start scaling your swing app:
-Dsun.java2d.dpiaware=false
[EDIT: Unfortunately, this flag no longer seems to work in Java 8, I was testing it in Java 6. Looks like this is a known issue.]
[EDIT 2: You can modify a Java 8 install to work correctly, using a program to modify the EXE manifests. I changed the setting from true to false in the manifests inside of java.exe and javaw.exe, and now my Swing programs scale correctly in Windows 10 high dpi. I used Resource Tuner to this.]
[Edit 3] Just use Java 9
ANSWER 3
Score 49
If you stumbled across this question but are actually looking for a solution that works on Linux, this is for you.
If you can add parameters to the java
binary which launches the application, you can use the option -D
to pass a value for the sun.java2d.uiScale
proprty to specify a scaling factor for Java2D. This will scale your application. The scaling factor value is a double. Make sure that you pass this option to the java
binary itself, not the launched Java application.
Example: Launch NearInfinity.jar with a UI scaling factor of 2.5
java -Dsun.java2d.uiScale=2.5 -jar ~/jars/NearInfinity.jar
Alternatively, you can set the GDK_SCALE
environment variable. Example:
GDK_SCALE=2 java -jar ~/jars/NearInfinity.jar
I found this ArchLinux Wiki article quite useful in general for running Linux on HiDPI systems, and some of the things might work on Windows as well.
ANSWER 4
Score 15
Solution: Run it on JRE 9.
This is because the Java runtime declared itself to be "DPI-aware" but didn't really supported it for AWT and Swing. Java applications were sized and rendered based on pixels rather than being properly scaled, this included HiDPI displays. Anyways, this has been recently solved. See the issue JEP 263: HiDPI Graphics on Windows and Linux and the upgrade.
So, increasing the font size does not work (because it does not increase the rest of the things); the jvm argument -Dsun.java2d.dpiaware=false
does not work (because it is not really supported); and the manifest file + registry edit (for Windows) just does not work.
Then, You need to run it on JRE 9 because it really supports this feature.
ANSWER 5
Score 7
To force all java executables to have "properties > compatibility > dpi scaling mode" set to "System", in an administrator powershell (win-x, a), run:
$javaexes = (Get-ChildItem -path "$env:ProgramFiles\Java","${env:ProgramFiles(x86)}\java" -filter java?.exe -recurse | Where-Object {$_.Name -match "java(|w).exe"} ).fullname
$javaexes | foreach {REG ADD "HKCU\Software\Microsoft\Windows NT\CurrentVersion\AppCompatFlags\Layers" /V $_ /T REG_SZ /D "~ DPIUNAWARE" /F}
to undo:
$javaexes | foreach {REG delete "HKCU\Software\Microsoft\Windows NT\CurrentVersion\AppCompatFlags\Layers" /V $_ /f}
Instead of HKCU you could use HKLM, but then you cannot change the dpi-scaling setting manually anymore in the properties > compatibility dialog of the java*.exe files.