Blog-Archiv

Donnerstag, 19. September 2019

Java Swing App Too Small on High Resolution Screen

The artifacts of software production are aging like living creatures. For some years I wondered how long my Java Swing desktop applications are going to survive. After JavaFX was promoted and web development became dominant, Swing apps are endangered species.

Swing was the first complete operating-system-independent object-oriented graphical user interface on planet Earth. (AWT renders platform-dependent, and although it could be used on all platforms, important components like trees and tables were missing, and still are.) Swing comes packaged with the Java Runtime Environment (JRE). Lots of people spent a lot of time creating Swing apps, and lots of users consumed them. Web apps still haven't reached the ease of use of desktop apps, and it looks like they don't strive for that.

The Problem

So time is washing away everything, and I saw my 20 years old Swing file explorer very small on the horizon of my high-DPI screen on a WINDOWS-10 machine (didn't encounter this problem on LINUX). Following screenshot is original size:

The title bar (not part of Swing) was the only natural thing, everything else was definitely much too small. Note how big the mouse cursor on bottom is compared to the toolbar icons.

There was no application-modification that could have caused this problem. Must be the hardware, or the operating system, or .... Swing being too naive for modern high-resolution screens?

The Solution

As we all believe in God, Google and Stackoverflow, I tried to find a fix for this. Here is the link that saved my Swing app for now:

Mind that the command-line option -Dsun.java2d.dpiaware=false does not work for Java 1.8. When you scroll downwards on that page, you find the real instruction:

  • → With WINDOWS Explorer, find your installed java.exe and javaw.exe interpreters (cmd.exe: where java ↵)

  • → For each, right-click "Properties"

  • → Change to "Compatibility" tab

  • → Click on "High DPI settings"

  • → Activate checkbox "Override high DPI scaling behavior"

  • → Choose "System" from "Scaling performed by" choice below

That means, you let the operating system take care of scaling the app for high DPI screens, not Swing. Generally Swing should be able to do that, but ....

After restarting my app it looked like this, in original size:

That really saved my day!




Keine Kommentare: