Java / Swing, how to work with various DPI settings of the screen and density?

Hello everyone. I recently encountered a problem that now some monitors have different DPI settings, some monitors are much denser, such as, for example, Apple Retina displays.

How to compensate for different DPI and density settings on different monitors using Java? Is it possible to scale controls on a single monitor of the same size. I know that when programming for Android, all measurements are in "DP", and you can specify different images for three different display densities.

Is there a way to select different images using Java / Swing for different display densities so that my application does not look blurry on monitors with higher densities? Or is it not so important or possible? I know that Chrome currently doesn't take DPI into account, but Internet Explorer and other apps do.

Thank you for your help. I have long been a Java developer. I had never thought about DPI before and wondered how I can do this :)

+5
source share
3 answers

First, trust the Look and Feel platform to select reasonable default sizes for text and controls. Then avoid the temptation to break these defaults. Here are a few heuristics:

  • ; .

  • .

  • .

  • Window.

  • .

+4

trashgod , , .

, , DPI, .

:

, , , . JLabel HTML, ( , ).

, , , (Tahoma 11 plain), . , user574171 , http://kynosarges.org/GuiDpiScaling.html DPI Java Swing Windows/Linux?. "Swing", WPF, JavaFX Swing . , "Swing a" , Tahoma 11 Plain. , , , , (Tahoma 11 Plain). , , , DPI.

(Tahoma), , , DPI. DPI, " ". "" DPI , , . , JLabel, DPI HTML-, , ( ).

, , , (Tahoma 11 plain) (.. Tahoma), , , , JLabel. , 125 DPI 3, .

:

, , , DPI. " " bullet in trashgod answer" . , , .

, DPI. , trashgod : "-, Look and Feel . ". , , ( ). , , "Horizontal Resizable" "Vertical Resizable", , DPI, .

, , . , . IE, , , 100% DPI DPI. , , , .

JScrollPane, , . / , JScrollPane - , DPI , .

: , JPanel DPI .

JTextField:

, , . columns - , . , . , .

JSpinner:

, . DPI .

:

DPI. , , Java. JLabel - DPI.

+3

JRE 9 ( ).

, Java ( ) "DPI-aware", AWT Swing. Java , , HiDPI. , . . JEP 263: HiDPI Windows Linux .

, ( ); jvm -Dsun.java2d.dpiaware=false ( ); + ( Windows) .

JRE 9, .

0

All Articles