JavaFX and HiDPI

This article is the third day of JavaFX Advent Calendar 2017. The second day is HASUNUMA Kenji's Easy JavaFX programming with afterburner.fx (1).

A brief note about the current status and settings of JavaFX HiDPI.

The standard display is 96 DPI (Dots Per Inch: 96 DPI is 96 pixels per inch), and the size of one pixel is 0.264 mm. On the other hand, for an ultra-high resolution display, for example, if the size is 13.3 inches and 2560 x 1440 pixels, the size of one pixel is 0.11 mm at 220 DPI.

A 12-pixel character is 3.2 mm in size on a standard display, but 1.4 mm on an ultra-high resolution display.

The size of what is displayed on the screen on an ultra-high resolution display is reduced to less than half on a standard display, which is inconvenient. As a workaround, the OS function expands the size of what is displayed on the screen. For Windows 10 OS, you can change "Resize text, apps, and other items" to 150%, 175%, 200%, etc. in the display settings.

In JavaFX, in the latest version of JDK 8, JDK 9, in the Windows environment, the display size is changed based on the enlargement ratio of this display size change.

For example, if you display a screen with Anchor Pane's Pref Width and Pref Height set to 320 and 200 and the font size set to 12px on an ultra-high resolution display, it will be enlarged according to the value of resizing in the OS settings. It shows.

To suppress this scaling and match the JavaFX pixel settings to the physical resolution of the original display, set the system property prism.allowhidpi to false.

The screen sizes when the system property prism.allowhidpi is set to true (default) and false are shown below.

image.png

The size of the graphics display with the system property prism.allowhidpi set changed is shown side by side.

image.png

Get DPI value with getDpi ()

JavaFX provides an API to get the DPI value of the display. The getDpi () method of the javafx.stage.Screen class.

The following is an example of the result of obtaining the DPI value using this API in an environment where the display resizing of the Windows OS is set to 150% on a display with a resolution of 2560x1440 at 13.3 inches.

Resize value of OS display settings prism.value of allowhidpi getDpi()Result of
150% true 147.0
150% false 221.0

Recommended Posts

JavaFX and HiDPI
JavaFX buttons and labels
Hello world with Kotlin and JavaFX
Drag and drop files with JavaFX
== and equals
Scaling and translation with JavaFX Canvas (Revenge)
JavaFx memorandum
A memo when fumbling and developing using JavaFX
I tried to link JavaFX and Spring Framework.
A simple rock-paper-scissors game with JavaFX and SceneBuilder