<AWT Dev> RFR: 8252015: [macos11] java.awt.TrayIcon requires updates for template images
Peter Zhelezniakov
peterz at openjdk.java.net
Tue Oct 6 08:21:45 UTC 2020
On Mon, 5 Oct 2020 19:14:23 GMT, Sergey Bylokhov <serb at openjdk.org> wrote:
>> [JDK-8252015: [macos11] java.awt.TrayIcon requires updates for template
>> images](https://bugs.openjdk.java.net/browse/JDK-8252015)
>> ### Problem
>> According to Apple's human interface guidelines, developers should use template images for tray icons. This way icons
>> look good when desktop theme or wallpaper change. On the API level, this means setting the `NSImage::isTemplate` flag.
>> Currently there's no way in Java to set this flag. Even if one uses a template (black and transparent pixels only)
>> image, MacOS will treat it as regular image. As a result, the image will not be visible when using dark theme. ###
>> Solution:
>> * If `sun.awt.enableTemplateImages` property is set, all tray icon images are treated as templates. It's the developers'
>> responsibility to ensure their images are indeed templates. This property allows us to avoid new API and accidental
>> behavior changes
>> * Value of this property is passed from Java into `NSImage::setTemplate`
>> * We need the tray icon image rendered by MacOS, so we use a button (rather than a view) to host the image
>
> Hi, Peter. You are welcome!
> Just an initial question about the template images, can you please provide some steps to reproduce this bug and so it
> will be possible to check that the fix solves it.
Hi Sergey, and thanks for looking into this!
Try the attached jar, it's a modified version of TrayIconDemo using a template icon taken from Wikimedia Commons.
Without the fix, or without `-Dsun.awt.enableTemplateImages`, the icon disappears if you switch to Dark theme. With the
fix and the property set, the system repaints it in white.
[TrayIconDemo.jar.zip](https://github.com/openjdk/jdk/files/5332241/TrayIconDemo.jar.zip)
-------------
PR: https://git.openjdk.java.net/jdk/pull/481
More information about the awt-dev
mailing list