Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I customize the program name in a traybar notification in AWT?

AWT's TrayIcon class has a method called displayMessage that shows a native OS message that in Windows 10 looks like this:

enter image description here

when called like this:

Image image = Toolkit.getDefaultToolkit().getImage(this.getClass().getResource("/isotype.png"));
final TrayIcon trayIcon = new TrayIcon(image, appName());
trayIcon.displayMessage("Caption", "Text text text", TrayIcon.MessageType.INFO);

How do I customize the string "Java(TM) Platform SE binary". When I build a self-contained exe for my application, it instead reads "Blah.exe" while I'd prefer it if reads just "Blah".

To package the application I'm using the JavaFX toolchain through the excellent JavaFX-Gradle-Plugin.

like image 982
pupeno Avatar asked Dec 12 '17 01:12

pupeno


2 Answers

One workaround is to use TrayIcon.MessageType.NONE. In this case you won't get the last line at all, but you won't get any INFO, WARNING or ERROR icon either.

But the good thing is that you can get your application icon in the displayed message. If you create the TrayIcon with some image like TrayIcon trayIcon = new TrayIcon(image, "Tooltip") and then package your application with JavaFX-Gradle-Plugin, displayMessage method will reuse this image and you will get something like this:

like image 193
Kirill Simonov Avatar answered Nov 15 '22 23:11

Kirill Simonov


The behaviour of TrayIcon is platform dependent. On a Mac, there's no such thing as "Java(TM) Platform SE binary", nor the executable.

If you want to change the behaviour on your platform, I guess you could play with awt.toolkit. See https://docs.oracle.com/javase/8/docs/api/java/awt/Toolkit.html#getDefaultToolkit--

like image 3
Johan Witters Avatar answered Nov 16 '22 01:11

Johan Witters