Tray Icon implementation for JavaFX applications. Say goodbye to using AWT's SystemTray icon, instead use a JavaFX Tray Icon.

Overview

FXTrayIcon

Maven Central Travis CI Build

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: Maven Central

Features & Screenshots

FXTrayIcon on Windows 10's tray

FXTrayIcon example

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

FXTrayIcon menu example

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)
  • showInfoMessage(String caption, String content)
    • or showInfoMessage(String content)
  • showWarnMessage(String caption, String content)
    • or showWarnMessage(String content)
  • showErrorMessage(String caption, String content)
    • or showErrorMessage(String content)

showMessage showInfoMessage showWarnMessage showErrorMessage

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.

Projects using FXTrayIcon

If your project uses FXTrayIcon, let us know via Pull Request, and we'll feature your project on this README.

Comments
  • [Feature Request] Restructure Builder class to support extended FXTrayIcon classes.

    [Feature Request] Restructure Builder class to support extended FXTrayIcon classes.

    I'm trying to extend FXTrayIcon to allow (in addtion) for a custom Menu when righitng clicking.

    I can do that fine with some reflection to get the trayIcon (all though would be nice if it was protected :D) However, supporting the builder in my extended even with some nasty reflection just isn't do-able i think because it always returns a FXTrayIcon constructed as such instead of my custom class. I'd have to copy your wonderful code and that just doesn't feel right.

    I tried settings it with reflection in the builder but its final so no bueno.

    Would it be possible to Generify builder? or make the trayIcon field (in the builder) protected and not final?

    Love the work btw! <3 🥇

    opened by NexRX 31
  • Application doesn't start

    Application doesn't start

    It appears the application hangs indefinitely on this line of code: FXTrayIcon

    Edit: Wrapping the icon instantiation and show in a SwingUtilities.invokeLater seems to fix the issue but the icon in the tray in just a black rectangle. But this is probably fault of GNOME for not having tray support natively (needs shell extension)

    opened by palexdev 13
  • Work on supporting Linux DEs

    Work on supporting Linux DEs

    Currently calling java.awt.SystemTray.getSystemTray() throws UnsupportedOperationException on Ubuntu 20.04 LTS.

    We should derive an alternative for adding tray support on at least Ubuntu 20.04 as it's one of the more commonly used Linux OSes. This entails figuring a way to add AppIndicator support for GNOME. This would also be nice to implement for KDE and XFCE desktop environments.

    I'm not so concerned with supporting those one-off Linux distros that use some obscure desktop environment, but if there's an easy way, then I will look into it.

    I can do this in my little free time, but if anyone feels like having a crack at it. I would greatly appreciate it.

    enhancement help wanted 
    opened by dustinkredmond 13
  • No way to detect mouse button/number of clicks on tray icon

    No way to detect mouse button/number of clicks on tray icon

    If I understand correctly, the only API made available for attaching an event to the tray is setOnAction() (onAction() with the Builder). This takes an ActionEvent, not a MouseEvent which seems strange. In particular, it interferes with the right click on the tray icon because the event is always fired regardless of which button is used or clicks used. For example, how do you fire something only on a left click and not on the right click/context menu?

    opened by dwalluck 12
  • [Feature Request] Disable default hide/show behavior

    [Feature Request] Disable default hide/show behavior

    It would be very useful to be able to manually manage all action events relating to the FXTrayIcon, at least relating to how left clicking the icon works.

    In my current project I am trying to have a behavior that shows a small popup window when the tray icon is single-clicked, but when double-clicked, the main window should show up. Currently, I only know of being able to use the setOnAction method for this, but it does not seem to override the default behavior of clicking on the FXTrayIcon.

    If anyone knows of a workaround to this, I found greatly appreciate it. Otherwise I would like to recommend some kind of system to make such actions easier to manage.

    opened by TornadoStorm 11
  • running on mac os , but get unexpected result

    running on mac os , but get unexpected result

    hi, @dustinkredmond

    I just run the RunableTest.java ,but the notifications are not as expected

    image

    the notification popup displays just like a normal window. with min, max, close, and a button on it.

    I have seen the posted screen shot of other guys, and it is just ok https://github.com/dustinkredmond/FXTrayIcon/issues/2

    here is my mac os info: image

    hope that I have described clear

    opened by littleboyonearth 9
  • Test on MacOS, ensure cross-platform function

    Test on MacOS, ensure cross-platform function

    FXTrayIcon is mostly built and tested on Windows 10. Theoretically, FXTrayIcon should work on any OS and desktop environment that supports the AWT SystemTray functionality.

    I do not readily have access to MacOS, but am aware that some features of FXTrayIcon work differently (or not at all) on MacOS. If anyone's primary machine runs MacOS, I could use the help in testing functionality and making any necessary changes to facilitate better operation.

    One such issue:

    setOnAction() does not cause the event to be triggered on double-click of the icon, this problem only exists on MacOS (to my knowledge) setOnClick() does work on MacOS for allowing single-click of the icon.

    In this case, maybe we could throw an UnsupportedOperationException or call into new code that would ameliorate the lack of functionality.

    good first issue 
    opened by dustinkredmond 9
  • Builder API inconsistent

    Builder API inconsistent

    Why is URL iconImagePath required to be passed into the builder constructor and not via a method? If the idea is to put required arguments in the constructor, then this doesn't make sense because there's a setGraphic() method, but no corresponding graphic() method for the builder. I see that it is probably to match the existing non-builder constructors, but I still think there should be a graphic() method and possibly others for the size. In any case, it seems a good idea to have the builders constructors and methods match the original, if possible.

    The API is setTooltip(), but toolTip() in the builder, whereas I think it should be tooltip(). It seems to be an inconsistency in AWT vs. JavaFX naming. I believe the AWT method uses a capital 'T', but JavaFX uses a lowercase 't' by convention.

    There's a setTrayIconTooltip() API which does the same thing, but the builder doesn't have such a method.

    opened by dwalluck 8
  • Added method addMenuItems

    Added method addMenuItems

    I added a method named addMenuItems, which allows the developer to add an unlimited number of MenuItems in a single method call. Also, if they create a MenuItem with the text 'separator' attached to it, it will add a separator, which conveniently allows the creation of a somewhat complex menu with one line of code:

    For example, this line of code

    icon.addMenuItems(menu1, menu2, separator, menu3, menu4, separator, exitMenu);

    Creates this menu

    Screen Shot 2021-09-08 at 4 54 20 AM

    Also, the check for duplicate menuItems still works as well.

    I also added a test Class called MultipleItemsOneLine

    opened by EasyG0ing1 8
  • Icon resolution on OSX

    Icon resolution on OSX

    I suspect that there may be no way to improve this, but the resolution of the tray icon on OSX is much poorer than other icons in the tray.

    With a JavaFX Image one can use the [email protected] format to supply a larger image which will be selected on a higher DPI screen. Is there any way to improve the image resolution here?

    opened by craigraw 8
  • A bug? Or am I doing something wrong?

    A bug? Or am I doing something wrong?

    Menus appear to be getting added to the list in the wrong order.

    This code:

    Menu dictionary = new Menu("Dictionary");
    dictionary.getItems().addAll(customDictionary, saveDictionary, loadDictionary, editDictionary);
    
    trayIcon.addMenuItems(saveSettings, loadSettings);
    trayIcon.addSeparator();
    trayIcon.addMenuItems(keyListener, paused);
    trayIcon.addMenuItem(dictionary);
    trayIcon.addSeparator();
    trayIcon.addMenuItems(show, hide);
    trayIcon.addExitItem("Exit");
    

    creates this menu: image

    For some reason the menu dictionary is between "Show" and "Hide to Tray" when it should come just before the second separator.

    Also this warning appears in the console, but I don't understand why as they are only added once.

    Jul 10, 2022 12:32:03 PM javafx.scene.control.Menu$6 onChanged
    WARNING: Adding MenuItem Custom Dictionary that has already been added to Keys
    Jul 10, 2022 12:32:03 PM javafx.scene.control.Menu$6 onChanged
    WARNING: Adding MenuItem Save Dictionary that has already been added to Keys
    Jul 10, 2022 12:32:03 PM javafx.scene.control.Menu$6 onChanged
    WARNING: Adding MenuItem Load Dictionary that has already been added to Keys
    Jul 10, 2022 12:32:03 PM javafx.scene.control.Menu$6 onChanged
    WARNING: Adding MenuItem Edit Dictionary that has already been added to Keys```
    opened by KaitlynEthylia 7
  • Only square icons possible?

    Only square icons possible?

    It looks like in the latest version only square icons are possible (on macos). In the older version I could also use an rectangular icon but in 4.0.1 it only accepts square icons even if I define the icon like 64x32. Is this on purpose?

    opened by HanSolo 6
Owner
Dustin Redmond
Hobbyist software engineer. I love to code, and enjoy working on web, server side, and desktop applications.
Dustin Redmond
Mod Launcher by Jbro129 fixed to work with Root instead of VA

Fixed Jbro ModLauncher Mod Launcher by Jbro129 fixed to work with Root instead of VA Code Used: https://github.com/jbro129/PG3D-JbroLauncher https://g

A Random Person 15 Jul 23, 2022
DataFX - is a JavaFX frameworks that provides additional features to create MVC based applications in JavaFX by providing routing and a context for CDI.

What you’ve stumbled upon here is a project that intends to make retrieving, massaging, populating, viewing, and editing data in JavaFX UI controls ea

Guigarage 110 Dec 29, 2022
Lib-Tile is a multi Maven project written in JavaFX and NetBeans IDE 8 and provides the functionalities to use and handle easily Tiles in your JavaFX application.

Lib-Tile Intention Lib-Tile is a multi Maven project written in JavaFX and NetBeans IDE and provides the functionalities to use and handle easily Tile

Peter Rogge 13 Apr 13, 2022
To quickly integrate your applications into the EdgeGallery platform, we provide the toolchain project to help developers quickly modify code and migrate applications to the platform.

Toolchain 工具链 工具链是MEC Developer开发者平台中的一个重要特性,当x86平台的App想要上车ARM平台时,底层的代码不可避免的需要进行修改或重写。 App提供者可以通过MEC Developer开发者平台中集成的工具链进行源代码分析,定位需要修改的源代码并根据指导意见进行修

EdgeGallery 19 Jan 7, 2022
Flash cards app using JavaFX, Scene Builder and persistence using Serialization with JAVA IO API

Flashcards - JavaFX , Scene Builder, Serialized Persistence JAVA IO API Main Scene that will show all the Decks in Flash Card App Add or Edit Cards in

Ali Raja 3 Nov 28, 2022
Auto updating launcher for JavaFX Applications

FXLauncher Auto updating launcher for JavaFX Applications. Combined with JavaFX native packaging, you get a native installer with automatic app update

Edvin Syse 694 Dec 27, 2022
A 3D chart library for Java applications (JavaFX, Swing or server-side).

Orson Charts (C)opyright 2013-2020, by Object Refinery Limited. All rights reserved. Version 2.0, 15 March 2020. Overview Orson Charts is a 3D chart l

David Gilbert 96 Sep 27, 2022
A Javafx Library for building MVC Applications.

A JavaFx Library For Making MVC Type Desktop Applications Installation requires Java jdk > 7 for windows requres openjdk-7 or 8 and openjfx for linux

Obi Uchenna David 38 Apr 30, 2022
A lightweight RCP framework for JavaFX applications.

WorkbenchFX The one and only framework to build large JavaFX Applications! Maven To use this framework as part of your Maven build simply add the foll

DLSC Software & Consulting GmbH 471 Jan 8, 2023
A 2D chart library for Java applications (JavaFX, Swing or server-side).

JFreeChart Version 2.0.0, not yet released. Overview JFreeChart is a comprehensive free chart library for the Java(tm) platform that can be used on th

David Gilbert 946 Jan 5, 2023
FlexBoxFX is a JavaFX implementation of CSS3 flexbox.

FlexBoxFX is a JavaFX implementation of CSS3 flexbox layout manager

null 5 Nov 4, 2021
A library of +70 ready-to-use animations for JavaFX

AnimateFX A library of ready-to-use animations for JavaFX Features: Custom animations Custom interpolators Play/Stop animation Play an animation after

Loïc Sculier 366 Jan 5, 2023
Provides a Java API to use the JavaScript library d3.js with the JavaFx WebView

javafx-d3 Provides a Java API for using the JavaScript library d3.js with JavaFx Applications. Many thanks to the authors of the projects gwt-d3 [1] a

null 98 Dec 19, 2022
Lobby System Template for a multiplayer java game, with chat and other features, using JavaFX and socket TCP (will be extended to UDP).

JavaFX-MultiplayerLobbySystem JavaFX lobby system for multiplayer games with chat, ready toggle and kick buttons, using socket TCP by default. Demo Cr

Michele Righi 7 May 8, 2022
CSGO cheat made in Java using JavaFX as the overlay and JNA for memory manipulation

CSGO-CHEAT CSGO cheat made in Java using JavaFX as the overlay and JNA for memory manipulation FEATURES RCS Triggerbot No Flash Third Person Rank Reve

Notorious 9 Dec 28, 2022
The snake and Ladders Game 🎲 for two players made using JavaFx with important concepts of OOPs🐍 🪜

The snake and Ladders Game made using JavaFx with important concepts of OOPs, done as a project for Advanced Programming course (CSE201) under Prof. Koteswar Rao Jerripothula

null 2 Sep 5, 2022
An image annotation desktop-application written in Java using the JavaFX application platform.

This is an image annotation desktop-application written in Java using the JavaFX application platform. It allows you to create bounding box annotations using rectangular and polygonal shapes. Annotations can be imported and saved from/to JSON files, Pascal VOC format XML-files or YOLO format TXT-files.

Markus Fleischhacker 31 Dec 4, 2022
JSilhouette provides additional shapes for Java applications

JSilhouette JSilhouette provides additional shapes for Java applications. Currently JavaFX is supported. Installing You can get the latest version of

Kordamp 39 Nov 7, 2022
An open source application to make your own android applications without coding!

Stif An Open source project for building Android Application at a go both with and without coding. This project was inspired from Scratch and Sketchwa

Nethical org 5 Aug 28, 2021