question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

JFrame and JInternalFrame SVG icons rendered in low resolution

See original GitHub issue

Hello!

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:closed
  • Created 2 years ago
  • Comments:7

github_iconTop GitHub Comments

1reaction
DevCharlycommented, May 12, 2021

For JFrame.setIconImage() you could use FlatSVGUtils.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#L64

Don’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…

… but we pack all code in a single jar.

Make sure that META-INF/versions directory from flatlaf.jar is included and the manifest contains Multi-Release: true. If one is missing, you probably get low-res images if using FlatLaf MultiResolutionImageSupport class.

0reactions
DevCharlycommented, May 14, 2021

Did you mean the embedded menu bar mode for JFrame?

Yes.

It takes 20x20 image (for 125%), so it seems working.

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 to SunToolkit.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.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Can I supply image icons in Java in a higher resolution to ...
All icons are available as PNG or SVG files. To illustrate the problem, let me first show you two screenshots in the normal...
Read more >
FlatLaf/CHANGELOG.md at main - GitHub
Native window decorations (Windows 10/11 only): Fixed rendering artifacts on HiDPI ... Extras: Fixed concurrent loading of SVG icons on multiple threads.
Read more >
C-Index (Java SE 10 & JDK 10 ) - Oracle Help Center
cacheIcon(File, Icon) - Method in class javax.swing.plaf.basic.BasicFileChooserUI. ... Specifies the type of camera use for rendering this Scene .
Read more >
Software Development v.2 Unit 5 Flashcards - Quizlet
Study with Quizlet and memorize flashcards containing terms like SWING AND AWT, graphical user interface, Abstract Window Toolkit and more.
Read more >
Bug List - JogAmp
1305, Jogl, opengl, sgothel, IN_P, ---, GLCanvas failed to initialize GL3(bc), GL4(bc) in SWING JFrame. GLJPanel succeed. 2020-01-05.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found