JFrame and JInternalFrame SVG icons rendered in low resolution
See original GitHub issueHello!
I use FlatSVGIcon
to set in JInternalFrame.setFrameIcon()
and custom MultiResolutionImage
based on FlatSVGIcon
for JFrame.setIconImage()
(unfortunately JFrame does not take Icon, only Image). I found that in v. 1.1.2 in our deployment build the icons of the frame and internal frame in hi-res mode (Windows/Mac OS retina) are rendered in low resolution (smooth and pixelized). But icons looks OK if I run the app from the IDE. All other icons on JButtons, in menus, etc. are OK. I don’t understand what is the difference between running from the IDE and the deployment build, the only thing that can matter is that our code is obfuscated (ProGuard). The library code is not obfuscated, but we pack all code in a single jar.
I’m sorry for such uncertain description, I will continue to investigate the issue to find some minimal (un-)working prototype to work with. There was no such issue in v. 0.46 that we used before.
I found the issue with JFrame icon first and tried to fix it with our implementation of MultiResolutionImage
based on FlatSVGIcon
. I experimentally fixed the issue by returning a default size image in getBaseImage()
instead of 128x128 image that this method returned before. Overall, when running from IDE (125% size in Windows), only getResolutionVariants()
and two getResolutionVariant()
are invoked for 20x20 and 40x40 (frame icon and taskbar icon, I suppose). But in deployment build also getBaseImage()
is invoked. I don’t understand what’s the difference and will update the issue with new information.
Issue Analytics
- State:
- Created 2 years ago
- Comments:7
For
JFrame.setIconImage()
you could useFlatSVGUtils.createWindowIconImages()
, as used in the FlatLaf Demo: https://github.com/JFormDesigner/FlatLaf/blob/9edaf5892949523096a1270e45b16b06e4fb4d68/flatlaf-demo/src/main/java/com/formdev/flatlaf/demo/DemoFrame.java#L64Don’t know whether Java multi-resolution images work for window title bars, especially when FlatLaf custom window decorations are not enabled or not available (Linux or macOS).
If FlatLaf custom window decorations are enabled, it would be optimal to paint SVG directly in window title bar, but this not yet the case… will look into this…
Make sure that
META-INF/versions
directory fromflatlaf.jar
is included and the manifest containsMulti-Release: true
. If one is missing, you probably get low-res images if using FlatLafMultiResolutionImageSupport
class.Yes.
But only if 20x20 is in the list of resolution variants. My above code snippet has only 16x16.
I’ve now changed handling of multi-resolution images in
FlatTitlePaneIcon
. It is now similar toSunToolkit.getScaledIconImage()
.Previously
MultiResolutionImage.getResolutionVariants()
was used to get all images variants and then the resulting list was queried for best matching size. This has the disadvantage that all the variant images needs to be created and only the (predefined) variant sizes are supported.Now
MultiResolutionImage.getResolutionVariant(width, height)
is used to request a image for needed size. This allows the multi-resolution image to create a image on demand for any needed size from SVG. And only used images needs to be created.https://github.com/JFormDesigner/FlatLaf/blob/8998371caea610ee8f931f4ad2191fe2913a5fe6/flatlaf-core/src/main/java/com/formdev/flatlaf/ui/FlatTitlePaneIcon.java#L46-L51
https://github.com/JFormDesigner/FlatLaf/blob/8998371caea610ee8f931f4ad2191fe2913a5fe6/flatlaf-extras/src/main/java/com/formdev/flatlaf/extras/FlatSVGUtils.java#L62-L80
BTW I’ve tested this also on macOS and Linux and it turns out that multi-resolution images are not supported for window icons on these platforms.