• Stars
    star
    328
  • Rank 128,352 (Top 3 %)
  • Language
    Java
  • License
    MIT License
  • Created over 4 years ago
  • Updated 7 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

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

FXTrayIcon

Maven Central Travis CI Build

Library 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();

Or use Builder Style

FXTrayIcon icon = new FXTrayIcon.Builder(stage, iconURL).menuItem("Menu 1", e-> myMethod()).addExitItem().show().build();

Click here for a Builder tutorial

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

CheckMenuItems

FXTrayIcon now supports the use of CheckMenuItems - See Javadocs for specifics.

FXTCheck

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)

      showMessage

  • showInfoMessage(String caption, String content)

    • or showInfoMessage(String content)

      showInfoMessage

  • showWarnMessage(String caption, String content)

    • or showWarnMessage(String content)

      showWarnMessage

  • showErrorMessage(String caption, String content)

    • or showErrorMessage(String content)

      showErrorMessage

Supported operating systems

OS Support Status Unsupported Features
Windows 11 Fully supported N/A
Mac OS Partially supported In the displayMessage() methods. Custom notification icons are not supported in AppleScript calls, but the TrayIcon is.
Linux Partially supported Some desktop environments that support java.awt.SystemTray are supported. Many are not. You should not rely on the isSupported method as a matter of truth, testing on individual desktop environments is strongly encouraged.

Call FXTrayIcon.isSupported() to see if the current platform supports the system tray.

Access to TrayIcon

Being a JavaFX library, much care has gone into keeping the AWT portions of the library out of sight within your IDE while using FXTrayIcon. However, we realize that there are situations where it would be useful to have access to the underlying TrayIcon awt object, so this can be done in two different ways.

  • You can extend FXTrayIcon and in that extended class, you can access the getTrayIcon() protected method.
  • Once you have FXTrayIcon instantiated, you can call the getRestricted() method then gain access to the TrayIcon object through that method.

Projects using FXTrayIcon

  • JDKMon - A tool that monitors your installed JDK's and informs you about updates.
  • GlucoStatusFX - Glucose status monitor for Nightscout implemented in JavaFX.
  • GistFX - A utility that makes managing and organizing your GitHub Gists easy and convenient.

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

More Repositories

1

FXAlert

JavaFX Alerts made easy. Easily create alerts, notifications, input dialogs, and more...
Java
16
star
2

JavaFXTableMapper

Eliminates boilerplate code associated with creating and filling JavaFX TableViews.
Java
10
star
3

SharePointAPI

A Java wrapper API for the SharePoint library that handles username/password authorization. Allows API access without a token.
Java
8
star
4

abap-examples

SAP ABAP Programming Examples
ABAP
7
star
5

bcrypt-generator

JavaFX GUI for creating/validating BCrypt (enhanced blowfish cipher) hashes
Java
6
star
6

ClipBoardPlusPlus

ClipBoard++ A simple JavaFX application for saving clipboard text, aka a clipboard history manager
Java
5
star
7

SimplePDFMerger

Extremely light-weight (one file) JavaFX program to merge multiple PDF files
Java
4
star
8

GroovyServer

Run and schedule GroovyScripts from an easy-to-use Java web application.
HTML
4
star
9

GistFX

A desktop client for working with GitHub Gists
Java
4
star
10

NotiFX

Cross-platform JavaFX library for notifications
Java
3
star
11

TimeCategory

Java wrapper for Groovy's TimeCategory class
Java
3
star
12

RustNote

Simple Rust command line application for creating/displaying text based notes
Rust
3
star
13

CSVUtils

Small library for working with delimited files
Java
2
star
14

ReflectDB

Lightweight tool to provide ORM and facilitate quick table creation using straightforward annotations.
Java
2
star
15

javascript-examples

Set of examples in vanilla JavaScript/CSS/HTML
HTML
2
star
16

SQLiteToCSV

Command line tool written in C language to export SQLite data as a CSV file.
C
2
star
17

sparkfx

A desktop client that makes building/testing REST APIs easy. Backed by the Spark Java framework, the possibilities are endless.
Java
2
star
18

LiteORM

Java
2
star
19

FXCharts

A tool to quickly render JavaFX's built in charts
Java
1
star
20

NotepadPlusPlus-ABAP-UDL

ABAP UDL (User Defined Language) for Notepad++
1
star
21

jhooks

Because sometimes it's easier to define stuff up front, then run it later, or in groups, or in new threads
Java
1
star
22

SAPABAP

SAP ABAP Projects
1
star