{"id":13777323,"url":"https://github.com/dustinkredmond/FXTrayIcon","last_synced_at":"2025-05-11T11:33:27.945Z","repository":{"id":37891174,"uuid":"289370092","full_name":"dustinkredmond/FXTrayIcon","owner":"dustinkredmond","description":"Tray Icon implementation for JavaFX applications. Say goodbye to using AWT's SystemTray icon, instead use a JavaFX Tray Icon.","archived":false,"fork":false,"pushed_at":"2024-05-20T20:10:18.000Z","size":14789,"stargazers_count":329,"open_issues_count":9,"forks_count":26,"subscribers_count":9,"default_branch":"main","last_synced_at":"2024-11-05T04:42:21.062Z","etag":null,"topics":["awt","awt-menuitems","javafx","javafx-applications","javafx-menuitems","javafxtrayicon","systemtray","tray-icon","trayicon"],"latest_commit_sha":null,"homepage":"","language":"Java","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/dustinkredmond.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":".github/FUNDING.yml","license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null},"funding":{"github":"dustinkredmond"}},"created_at":"2020-08-21T21:40:50.000Z","updated_at":"2024-10-28T14:04:02.000Z","dependencies_parsed_at":"2024-01-06T22:29:45.822Z","dependency_job_id":"f2f07969-a8ba-442a-bcad-b47990274fa4","html_url":"https://github.com/dustinkredmond/FXTrayIcon","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dustinkredmond%2FFXTrayIcon","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dustinkredmond%2FFXTrayIcon/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dustinkredmond%2FFXTrayIcon/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dustinkredmond%2FFXTrayIcon/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/dustinkredmond","download_url":"https://codeload.github.com/dustinkredmond/FXTrayIcon/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":225043095,"owners_count":17411927,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["awt","awt-menuitems","javafx","javafx-applications","javafx-menuitems","javafxtrayicon","systemtray","tray-icon","trayicon"],"created_at":"2024-08-03T18:00:41.557Z","updated_at":"2025-05-11T11:33:27.914Z","avatar_url":"https://github.com/dustinkredmond.png","language":"Java","funding_links":["https://github.com/sponsors/dustinkredmond"],"categories":["Community","Libraries, Tools and Projects"],"sub_categories":["Libraries"],"readme":"# FXTrayIcon\n\n[![Maven Central](https://img.shields.io/maven-central/v/com.dustinredmond.fxtrayicon/FXTrayIcon.svg?label=Maven%20Central)](https://search.maven.org/search?q=g:%22com.dustinredmond.fxtrayicon%22%20AND%20a:%22FXTrayIcon%22)\n[![Travis CI Build](https://travis-ci.com/dustinkredmond/FXTrayIcon.svg?branch=main)](https://travis-ci.com/dustinkredmond/FXTrayIcon)\n\nLibrary for use in JavaFX applications that makes adding a System Tray icon easier.\nThe FXTrayIcon class handles all the messy AWT and Swing parts of constructing an icon,\ndisplaying notifications, creating a context menu, etc. This means that users of FXTrayIcon can\nwork solely with its public API and JavaFX classes that they are already familiar with.\n\nCheck out the [runnable test application](./src/test/java/com/dustinredmond/fxtrayicon/RunnableTest.java) in the test directory for an example of how this works.\n\n## Usage\n\nFrom within your JavaFX application, adding a tray icon is as simple as two lines of code.\nYes, really, that's it!\n\n```java\n// Pass in the app's main stage, and path to the icon image\nFXTrayIcon icon = new FXTrayIcon(stage, getClass().getResource(\"someImageFile.png\"));\nicon.show();\n```\n\n## Or use Builder Style\n\n```java\nFXTrayIcon icon = new FXTrayIcon.Builder(stage, iconURL).menuItem(\"Menu 1\", e-\u003e myMethod()).addExitItem().show().build();\n```\n\n[Click here for a Builder tutorial](https://github.com/dustinkredmond/FXTrayIcon/blob/main/BuilderTutorial.md)\n\n## How do I add to my project\n\nThe project is available as a Maven dependency on Central. Add the following to POM.xml\n\n```xml\n\u003cdependency\u003e\n  \u003cgroupId\u003ecom.dustinredmond.fxtrayicon\u003c/groupId\u003e\n  \u003cartifactId\u003eFXTrayIcon\u003c/artifactId\u003e\n  \u003cversion\u003e\u003c!--See Below --\u003e\u003c/version\u003e\n\u003c/dependency\u003e\n```\n\nOr, if using Gradle to build, add the below to your Gradle build file\n\n```groovy\ncompile group: 'com.dustinredmond.fxtrayicon', name: 'FXTrayIcon', version: '\u003csee below\u003e'\n```\n\nYou can even use it from a Groovy script!\n\n```groovy\n@Grapes(\n  @Grab(group='com.dustinredmond.fxtrayicon', module='FXTrayIcon', version='\u003csee below\u003e')\n)\n```\n\n*Note, for the current stable version number, use the following:*\n[![Maven Central](https://img.shields.io/maven-central/v/com.dustinredmond.fxtrayicon/FXTrayIcon.svg?label=Maven%20Central)](https://search.maven.org/search?q=g:%22com.dustinredmond.fxtrayicon%22%20AND%20a:%22FXTrayIcon%22)\n\n## Features \u0026 Screenshots\n\n### CheckMenuItems\n\nFXTrayIcon now supports the use of CheckMenuItems - See Javadocs for specifics.\n\n![FXTCheck](./img/FXTCheck.gif)\n\n## Animated Icons\n\nFXTrayIcon now offers a convenient way to animate the icon in the tray. This is great \nfor things like letting the user know when the program is processing something or even \nto subtly get their attention.\n\n![animation](./img/animation.gif)\n\nThe way you use it is straightforward. First, create all the frames of the animation and \nsave each frame into a file. The turning circle above, for example, took 45 files to create. \nOnce you have the files, \nyou can load them into FXTrayIcon in one of two ways: Pass in `LinkedList\u003cjava.io.File\u003e` or \n`LinkedList\u003cjavafx.scene.image.Image\u003e`. \n\nFor example, create a `LinkedList\u003cFile\u003e` containing the `File` objects of each frame, \nand then pass them into FXTrayIcon using the Builder or after FXTrayIcon has been instantiated. \nWe recommend putting the files into their own folder; numbered in sequence, then create the \nlist from that folder.\n\nCreating the list:\n\n```Java\nFile[]  files = new File(\"path/to/my/imageFiles\").listFiles();\nLinkedList\u003cFile\u003e fileList = new LinkedList\u003c\u003e(Arrays.asList(files));\nfileList.sort(Comparator.comparing(File::getName));\n```\n\nUsing the list with the Builder:\n```Java\ntrayIcon = new FXTrayIcon.Builder(primaryStage, iconFile)\n    .animate(fileList, 75)\n    .addExitMenuItem(\"Exit\", e -\u003e Main.stopRunning())\n    .show()\n    .build();  \n```\n\nOr after instantiation:\n```Java\ntrayIcon.newAnimation(fileList, 75);\n```\n\nThe `.newAnimation()` method can also be used to replace an existing animation.\n\nThe number after `fileList` is the amount of time that each frame will be shown, specified in milliseconds. \n\nThese methods can be used to play and control the animation:\n\n```Java\ntrayIcon.play();\ntrayIcon.playFromStart();\ntrayIcon.stop();\ntrayIcon.pause();\ntrayIcon.pauseResume();\ntrayIcon.stopReset();\ntrayIcon.resetIcon();\n```\n\nUse these methods to get the state of the animation:\n```Java\ntrayIcon.isRunning();\ntrayIcon.isPaused();\ntrayIcon.isStopped();\n```\n\nAnd if you need access to the timeline of the animation for any reason, just use `trayIcon.getTimeline()`\n\nThere is a full working program in the test folder called Animation. It will show you everything you need \nto know. The JavaDocs are also available and are very thorough.\n\n\n### FXTrayIcon on Windows 10's tray\n\n![FXTrayIcon example](./img/fxtrayicon-1.png)\n\nAbove is an example of FXTrayIcon running on Windows 10, of course, you choose your own icon file.\nHere we used a link icon from [Icons8](https://www.icons8.com), they provide thousands of amazing\nicons for developers, both free (with an attribution) and paid.\n\n### Context Menu - uses JavaFX MenuItem\n\n![FXTrayIcon menu example](./img/fxtrayicon-2.png)\n\nAn example of FXTrayIcon's custom context menu, built using JavaFX MenuItems.\nSurprise, surprise, JavaFX MenuItems get translated into AWT MenuItems by FXTrayIcon,\nso there's no need to use those! A developer can work solely with JavaFX Menus and MenuItems.\n\n### Tray notifications\n\nThe following can be used to show notifications. Note that the `showMessage()` method\nuses the icon from FXTrayIcon in the notification, while the others use different icons\nto indicate the level of severity of the message.\n\n- `showMessage(String caption, String content)`\n    - or `showMessage(String content)`\n\n      ![showMessage](./img/showDefault.png)\n\n- `showInfoMessage(String caption, String content)`\n    - or `showInfoMessage(String content)`\n\n      ![showInfoMessage](./img/showInfo.png)\n\n- `showWarnMessage(String caption, String content)`\n    - or `showWarnMessage(String content)`\n\n      ![showWarnMessage](./img/showWarn.png)\n\n- `showErrorMessage(String caption, String content)`\n    - or `showErrorMessage(String content)`\n\n      ![showErrorMessage](./img/showError.png)\n\n## Supported operating systems\n\n| OS         | Support Status      | Unsupported Features                                                                                                                                                                                                                   |\n|------------|---------------------|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|\n| Windows 11 | Fully supported     | N/A                                                                                                                                                                                                                                    |\n| Mac OS     | Partially supported | In the `displayMessage()` methods. Custom notification icons are not supported in AppleScript calls, but the TrayIcon is.                                                                                                              |\n| 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. |\n\nCall `FXTrayIcon.isSupported()` to see if the current platform\nsupports the system tray.\n\n### Access to TrayIcon\n\nBeing 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\nunderlying TrayIcon awt object, so this can be done in two different ways.\n\n-   You can extend FXTrayIcon and in that extended class, you can access the `getTrayIcon()` protected method.\n-   Once you have FXTrayIcon instantiated, you can call the `getRestricted()` method then gain access to the TrayIcon object through that method.\n\n### About icon sizes\nThe nature of how FXTrayIcon needing to be a library that works side by side with Swing, because we still do not \nhave a native JavaFX means for utilizing the system tray, icon sizing can be problematic with different operating systems.\nIf you use the methods that do not require you to specify the icon size, then FXTrayIcon will use the best\nsize for whichever operating system you're running it on. Windows requires a slightly smaller size than Macs.\n\nThis animation feature does not have any options for specifying the size of the icon because it is best to just\nlet it use the defaults. However, if you still want to control the size of the icon and the animation icon,\nthen you can override the defauoy by using:\n\n```Java\n.setIconSize(width, height);\n.setIconSize(oneValueWH);\n```\n\nThen those values will become the default icon size that the Builder uses anywhere an icon size isn't required, \nand also the animation feature will use those values.\n\nYou can use that method in the build statement or after instantiation. The Builder will not build anything until\nthe end so that you have an opportunity to change those values if desired.\n\n## Projects using `FXTrayIcon`\n\n- [JDKMon](https://github.com/HanSolo/JDKMon) - A tool that monitors your installed JDK's and informs you about updates.\n- [GlucoStatusFX](https://github.com/HanSolo/glucostatusfx) - Glucose status monitor for Nightscout implemented in JavaFX.\n- [GistFX](https://github.com/RedmondSims/GistFX) - A utility that makes managing and organizing your GitHub Gists easy and convenient.\n- [NFC4PC](https://github.com/martinpaljak/NFC4PC) - Makes your desktop PC react to NFC tags by opening them just like a mobile phone.\n- [JFXCentral](https://www.jfx-central.com/) - Home to everything JavaFX related. Website is written in JavaFX with [JPro](https://www.jpro.one/) -  Desktop Version uses FXTrayIcon.\n\nIf your project uses FXTrayIcon, let us know via Pull Request, and we'll feature your project on this README.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdustinkredmond%2FFXTrayIcon","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdustinkredmond%2FFXTrayIcon","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdustinkredmond%2FFXTrayIcon/lists"}