13

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.

Pablo Fernandez
  • 279,434
  • 135
  • 377
  • 622
  • 2
    Use [launch4j](http://launch4j.sourceforge.net/index.html) Cross-platform Java executable wrapper (a custom launcher) – Akila Dec 12 '17 at 06:21
  • @aKilleR: that means changing my whole installer toolchain. What do I gain by using launch4j? – Pablo Fernandez Dec 12 '17 at 11:51
  • 1
    @Pablo, does this help? https://stackoverflow.com/questions/13683335/including-an-icon-into-a-self-contained-javafx-application-exe – Tarun Lalwani Dec 16 '17 at 13:33

4 Answers4

4

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:

Kirill Simonov
  • 8,257
  • 3
  • 18
  • 42
3

On my system (tried both Java 8u151 and Java 9.0.1 on Windows 10), with the minimal setup of build.gradle from javafx-gradle-plugin, I have not found any configuration option for that name, but I can control it: the packager simply takes the name of parent directory that contains my sources.

Example with "Foo Bar":
Executable name = "FooBar.exe"
Displayed name = "Foo Bar"
enter image description here

(What I don't get, then, is why you see "Blah.exe" instead of the name of your parent directory...)

Hugues M.
  • 19,846
  • 6
  • 37
  • 65
2

To change the pop-up text which in your posted screenshot is displayed as Java(TM) Platform SE binary in your Blah.exe to Blah you could use for example the Resource Hacker™.

Change in the section Version Info the value for FileDescription to Blah either interactive in the GUI or on commandline.

Find below a simple example which needs to be amended for your needs.

versioninfo.rc resource script containing the information for the VERSIONINFO resource

1 VERSIONINFO
{
BLOCK "StringFileInfo"
{
    BLOCK "00000409"
    {
        VALUE "FileDescription", "Blah"
    }
}

BLOCK "VarFileInfo"
{
    VALUE "Translation", 0x0000 0x0409
}
}

compile the resource script to a resource file

ResourceHacker.exe -open versioninfo.rc \
    -save versioninfo.res \
    -action compile 
    -log CONSOLE

add the resource to the executable

ResourceHacker.exe -open Blah.exe \
    -save Blah_new.exe \
    -resource versioninfo.res \
    -action addoverwrite \
    -mask VERSIONINFO,1,0 \
    -log CONSOLE

For completeness here the command to extract the VERSIONINFO from an EXE file.

 ResourceHacker.exe -open Blah.exe \
     -save versioninfo.rc \
     -action extract \
     -mask VERSIONINFO,, \
     -log CONSOLE
SubOptimal
  • 22,518
  • 3
  • 53
  • 69
  • The problem with this is that I cannot do anything to the .exe because in my build chain, creating the .exe and packaging it in the installer is an atomic operation (that's how javafxpackager works, which is what JavaFX-Gradle-plugin uses). – Pablo Fernandez Dec 18 '17 at 08:03
  • 1
    @Pablo As far as I know the `javafxpackager` doesn't create an `exe` file. The Gradle plugin uses `Inno Setup` (for EXE installers) or `WiX` (for MSI installers). – SubOptimal Dec 18 '17 at 09:29
  • Fair enough, it's the plug in that makes it an atomic operation and not javafxpackager. – Pablo Fernandez Dec 18 '17 at 09:53
  • 1
    @Pablo Would you mind to provide a [MCVE](https://stackoverflow.com/help/mcve). Based on the answer of [@Hugues M.](https://stackoverflow.com/users/6730571/hugues-m) it seems not to be the default behaviour. When I build the `minimal-setup-jfxnative` example provided by the `JavaFX-Gradle-Plugin` the created `exe` file does not even contain a `FileDescription` value. And the text `Java(TM) Platform SE binary`, in your screenshot, is comming from the `java.exe / javaw.exe` executable. So it would be interesting to reproduce your observed behaviour. – SubOptimal Dec 18 '17 at 11:35
2

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--

Johan Witters
  • 1,529
  • 11
  • 23