FXTrayIcon
Library intended for use in JavaFX applications that makes adding a System Tray icon easier. The FXTrayIcon class handles all the messy AWT and Swing parts of constructing an icon, displaying notifications, creating a context menu, etc. This means that users of FXTrayIcon can work solely with its public API and JavaFX classes that they are already familiar with.
Check out the runnable test application in the test directory for an example of how this works.
Usage
From within your JavaFX application, adding a tray icon is as simple as two lines of code. Yes, really, that's it!
// Pass in the app's main stage, and path to the icon image
FXTrayIcon icon = new FXTrayIcon(stage, getClass().getResource("someImageFile.png"));
icon.show();
How do I add to my project
The project is available as a Maven dependency on Central. Add the following to POM.xml
<dependency>
<groupId>com.dustinredmond.fxtrayicon</groupId>
<artifactId>FXTrayIcon</artifactId>
<version><!--See Below --></version>
</dependency>
Or, if using Gradle to build, add the below to your Gradle build file
compile group: 'com.dustinredmond.fxtrayicon', name: 'FXTrayIcon', version: '<see below>'
You can even use it from a Groovy script!
@Grapes(
@Grab(group='com.dustinredmond.fxtrayicon', module='FXTrayIcon', version='<see below>')
)
Note, for the current stable version number, use the following:
Features & Screenshots
FXTrayIcon on Windows 10's tray
Above is an example of FXTrayIcon running on Windows 10, of course, you choose your own icon file. Here we used a link icon from Icons8, they provide thousands of amazing icons for developers, both free (with an attribution) and paid.
Context Menu - uses JavaFX MenuItem
An example of FXTrayIcon's custom context menu, built using JavaFX MenuItems. Surprise, surprise, JavaFX MenuItems get translated into AWT MenuItems by FXTrayIcon, so there's no need to use those! A developer can work solely with JavaFX Menus and MenuItems.
Tray notifications
The following can be used to show notifications. Note that the showMessage()
method uses the icon from FXTrayIcon in the notification, while the others use different icons to indicate the level of severity of the message.
showMessage(String caption, String content)
- or
showMessage(String content)
- or
showInfoMessage(String caption, String content)
- or
showInfoMessage(String content)
- or
showWarnMessage(String caption, String content)
- or
showWarnMessage(String content)
- or
showErrorMessage(String caption, String content)
- or
showErrorMessage(String content)
- or
Supported operating systems
OS | Support Status | Unsupported Features |
---|---|---|
Windows 10 | Fully supported | N/A |
Mac OS | Partially supported | In the displayMessage() methods. Custom icons are not supported in AppleScript calls. |
Linux | Partially supported | Some desktop environments that support java.awt.SystemTray are supported. Most are not. |
Call FXTrayIcon.isSupported()
to see if the current platform supports the system tray.
FXTrayIcon
Projects using If your project uses FXTrayIcon, let us know via Pull Request, and we'll feature your project on this README.