简体   繁体   中英

How can I scale fonts on a high resolution screen?

On a high-resolution screen (my example, Windows 8.1) is my Java application. The menu in particular is very small, and it's almost impossible to select a menu item.

In the normal screens (72 DPI) everything is OK.

Font with a fixed size (in my case it would have <80px), is a poor choice. 72 DPI screens show it very large.

How can I make the fonts scalable so that the program conforms to its size, or the user gets the possibility of setting?

You can change the default font size in a single place by accessing your PLAF: Java Swing on high-DPI screen

but this will still make the application look bad, because inter-component spaces will be in pixels, and therefore will not scale with font size. See http://www.javalobby.org/java/forums/t101878.html for a longer discussion.

My recommendation is to use a DPI-aware layout library, such as MigLayout , which supports specifying sizes either in pixels or in DPI-aware mm or cm. You can then couple both font-scaling and DPI-aware spacing by using FontMetrics to find the correct size for your fonts.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM