Font DPI and icon scaling

Discuss here any questions about the WebLaF library.
Bugs can be posted directly to GitHub issues tracker.

Font DPI and icon scaling

Postby szptdlo » Wed Jul 01, 2015 4:06 pm

Hi.

I've got a problem with Swing app running on high resolution (but small size) screens.

Nowadays It's pretty popular to have 14" screen with 5k pixels (vide Retina Display, etc). How to deal with such a displays and typical Swing app?

I'm looking for some decent solution for proper GUI scaling. Not only font scalling but also margins, paddings and icons like: checkbox tick, radiobutton, spinner arrows, slider thumb, scroll bars, etc...

Is this possible to size up all fonts using WebLookAndFeel? (I guess it is using UIManager.put... - but maybe there is a better way)

So the more important, is this possible to scale up checkbox tick, radiobutton, slider thumb, etc?

I saw that there is a 9patch support in WebLookAndFeel so maybe there is something like that.

Thanks.
szptdlo
 
Posts: 2
Joined: Wed Jul 01, 2015 3:52 pm

Re: Font DPI and icon scaling

Postby mgarin » Wed Jul 01, 2015 4:57 pm

So far WebLaF doesn't support high-DPI screens out of the box.
And generally all of the L&F I know about don't support those as well, even the official L&Fs like Nimbus.

This might look like a rather small issue, but with Swing this actually goes really deep.
All UIs paint their view using pixel metrics which doesn't depend on any scaling factor.
So basically you would have to change every UI painting algorithm to achieve UI scaling right now.

Though as far as I know Swing UI gets scaled by some systems (confirmed on Windows 8 for example) so you don't really need to do anything. Scaled UI doesn't really look well - it seems that it simply enlarges final image onto which UI is painted and displays it on the screen. Of course it mostly looks fine on high DPI screens because in the end the real size of the UI is the same as on the low DPI screen w/o this sizing, but it still has some side-effects like slightly blurred text.

The best option you have right now to write application for high-DPI screen is Java FX which has become much better lately and is now pretty stable and efficient.

Probably I will be looking towards high-DPI screen support in future versions of L&F, but I'm not yet sure that it is even possible without any annoying side-effects like performance or painting issues.
User avatar
mgarin
Site Admin
 
Posts: 223
Joined: Mon Apr 16, 2012 1:01 pm
Location: Russia, Saint-Petersburg

Re: Font DPI and icon scaling

Postby szptdlo » Wed Jul 01, 2015 5:21 pm

Many thanks for an immediate answer. But your answer is something I was afraid of.

Recent years I've been working in team where we develop pretty large system in Swing. And we have already about 200 different forms in Swing so I was hoping for some "quick" solution with your L&F :)

I'm starting to test JavaFX now, maybe that will be better solution for next major version. Thanks very much for your advise.
szptdlo
 
Posts: 2
Joined: Wed Jul 01, 2015 3:52 pm

Re: Font DPI and icon scaling

Postby mgarin » Wed Jul 01, 2015 7:27 pm

Decision should depend on specifics of your product. High-DPI screens aren't widely used (mostly Mac users I suppose) so if that requires complete revamp of Swing application code it might not worth it - for example that is exactly the case for a lot of our own products. Swing will still be good and usable for a long time.

Though if you are writing a completely new product you might look at Java FX to measure pros and cons of the technology and whether you want to try it out in your new product or not.

In any case - I am going to continue support and develop WebLaF for Swing.
Also with time I will probably also add an FX alternative for WebLaF with similar features.
User avatar
mgarin
Site Admin
 
Posts: 223
Joined: Mon Apr 16, 2012 1:01 pm
Location: Russia, Saint-Petersburg

Re: Font DPI and icon scaling

Postby rednoah » Sun Dec 27, 2015 5:51 pm

Would it be possible to have a scale factor which scales the entire UI (and mouse events) by some fixed scale factor like 2x or 4x?

So instead of using a huge font size (like Windows LaF does) to "scale" things (and break every layout) it seems that just scaling everything on the Graphics2D Swing drawing level / AWT event level might be an easy solution (though I guess the necessary hooks don't exist, making this not easy at all).
rednoah
 
Posts: 2
Joined: Sun Dec 27, 2015 5:32 pm

Re: Font DPI and icon scaling

Postby rednoah » Sun Dec 27, 2015 9:13 pm

Something seems to be in the works for Java 9 -> http://openjdk.java.net/jeps/263
rednoah
 
Posts: 2
Joined: Sun Dec 27, 2015 5:32 pm

Re: Font DPI and icon scaling

Postby mgarin » Mon Dec 28, 2015 6:28 pm

rednoah wrote:Would it be possible to have a scale factor which scales the entire UI (and mouse events) by some fixed scale factor like 2x or 4x?


Not in the closest update, but now I am pretty sure it is possible with the new way all components are painted. It will require some adjustments and improvements, but it is possible.

Also it doesn't really matter that much whether it is 2x or 1.25x as current Graphics2D API allows double coordinates and properly paints everything with AA enabled. They should look descent in the situations they are supposed to be used in - on HiDPI screens.

rednoah wrote:So instead of using a huge font size (like Windows LaF does) to "scale" things (and break every layout) it seems that just scaling everything on the Graphics2D Swing drawing level / AWT event level might be an easy solution (though I guess the necessary hooks don't exist, making this not easy at all).


Yes, scaling just font size doesn't really make much sense in case of UI. The whole UI should properly scale according to the scaling factor.

I will be looking into UI scaling for sure after making the base system stable and polished.
For now I have added a separate issue on GitHub tracker for this enhancement: #352

And thanks for the link, it seems that some related enhancements might actually be released in JDK at some point, but I'm not yet sure how those will work in the end until I get my hands on them. In case those changes will already be available by the time I get to the scaling enhancement I will certainly try them first and see if it can replace manual UI scaling.
User avatar
mgarin
Site Admin
 
Posts: 223
Joined: Mon Apr 16, 2012 1:01 pm
Location: Russia, Saint-Petersburg


Return to Questions

Who is online

Users browsing this forum: No registered users and 1 guest

cron