GithubHelp home page GithubHelp logo

dustinkredmond / fxtrayicon Goto Github PK

View Code? Open in Web Editor NEW
318.0 9.0 25.0 14.44 MB

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

License: MIT License

Java 100.00%
trayicon awt javafx systemtray tray-icon javafx-applications javafx-menuitems awt-menuitems javafxtrayicon

fxtrayicon's Introduction

Thanks for visiting

I'm a database administrator with a love for development. I enjoy creating developer tools as well as desktop applications. I work primarily with Java, Python, and C/C++ in my free time.

A few things I'm working on in my free time:

  • An implementation of the System Tray Icon for JavaFX applications, JavaFX doesn't support this, so someone had to write it (FXTrayIcon)
  • Library for easily displaying input/alert dialogs in JavaFX programs (FXAlert)
  • A minimalistic pure Java non-ORM framework for SQLite. Kick those database relations to the side, while still using a SQLite database for storage. The DBA in me hates this one, but it's amazing for prototyping. (LiteORM)
  • A multi user web-based application to let users run Groovy scripts either on demand or on a schedule. Great for simple or complex scripts, automate tasks with easy script definitions. Run scripts daily, hourly, each minute, or use a cron expression for even more customizability. (GroovyServer)
  • A desktop client to easily create/modify web API routes in real time based on the Spark Java framework. Users of Express JS will love the familiarity this application provides. (SparkFX)

Please consider starring any of my repositories that you find interesting. If you'd really like to help me out, consider sponsoring me on GitHub sponsors. My email address is on my GitHub profile, so please don't hesitate to shoot me a message with questions/concerns/etc.

fxtrayicon's People

Contributors

atelechev avatar azplanlos avatar dustinkredmond avatar easyg0ing1 avatar hansolo avatar j0b10 avatar jorge-fern avatar martinpaljak avatar nexrx avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

fxtrayicon's Issues

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.

NullPointerException when null MenuItem()

I have used codding somethings like this:

MenuItem mnuBuizName = new MenuItem();
trayIcon.addMenuItem(mnuBuizName);

Error:

Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException: Cannot invoke "String.equals(Object)" because the return value of "java.awt.MenuItem.getLabel()" is null
	at com.dustinredmond.fxtrayicon.FXTrayIcon.isNotUnique(FXTrayIcon.java:1434)
	at com.dustinredmond.fxtrayicon.FXTrayIcon.addMenuItemPrivately(FXTrayIcon.java:989)
	at com.dustinredmond.fxtrayicon.FXTrayIcon.lambda$addMenuItem$9(FXTrayIcon.java:966)
	at java.desktop/java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:318)
	at java.desktop/java.awt.EventQueue.dispatchEventImpl(EventQueue.java:771)
	at java.desktop/java.awt.EventQueue$4.run(EventQueue.java:722)
	at java.desktop/java.awt.EventQueue$4.run(EventQueue.java:716)
	at java.base/java.security.AccessController.doPrivileged(AccessController.java:399)
	at java.base/java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:86)
	at java.desktop/java.awt.EventQueue.dispatchEvent(EventQueue.java:741)
	at java.desktop/java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:203)
	at java.desktop/java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:124)
	at java.desktop/java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:113)
	at java.desktop/java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:109)
	at java.desktop/java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:101)
	at java.desktop/java.awt.EventDispatchThread.run(EventDispatchThread.java:90)
Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException: Cannot invoke "String.equals(Object)" because the return value of "java.awt.MenuItem.getLabel()" is null
	at com.dustinredmond.fxtrayicon.FXTrayIcon.isNotUnique(FXTrayIcon.java:1434)
	at com.dustinredmond.fxtrayicon.FXTrayIcon.addMenuItemPrivately(FXTrayIcon.java:989)
	at com.dustinredmond.fxtrayicon.FXTrayIcon.lambda$addMenuItem$9(FXTrayIcon.java:966)
	at java.desktop/java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:318)
	at java.desktop/java.awt.EventQueue.dispatchEventImpl(EventQueue.java:771)
	at java.desktop/java.awt.EventQueue$4.run(EventQueue.java:722)
	at java.desktop/java.awt.EventQueue$4.run(EventQueue.java:716)
	at java.base/java.security.AccessController.doPrivileged(AccessController.java:399)
	at java.base/java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:86)
	at java.desktop/java.awt.EventQueue.dispatchEvent(EventQueue.java:741)
	at java.desktop/java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:203)
	at java.desktop/java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:124)
	at java.desktop/java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:113)
	at java.desktop/java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:109)
	at java.desktop/java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:101)
	at java.desktop/java.awt.EventDispatchThread.run(EventDispatchThread.java:90)
Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException: Cannot invoke "String.equals(Object)" because the return value of "java.awt.MenuItem.getLabel()" is null
	at com.dustinredmond.fxtrayicon.FXTrayIcon.isNotUnique(FXTrayIcon.java:1434)
	at com.dustinredmond.fxtrayicon.FXTrayIcon.addMenuItemPrivately(FXTrayIcon.java:989)
	at com.dustinredmond.fxtrayicon.FXTrayIcon.lambda$addMenuItem$9(FXTrayIcon.java:966)
	at java.desktop/java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:318)
	at java.desktop/java.awt.EventQueue.dispatchEventImpl(EventQueue.java:771)
	at java.desktop/java.awt.EventQueue$4.run(EventQueue.java:722)
	at java.desktop/java.awt.EventQueue$4.run(EventQueue.java:716)
	at java.base/java.security.AccessController.doPrivileged(AccessController.java:399)
	at java.base/java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:86)
	at java.desktop/java.awt.EventQueue.dispatchEvent(EventQueue.java:741)
	at java.desktop/java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:203)
	at java.desktop/java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:124)
	at java.desktop/java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:113)
	at java.desktop/java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:109)
	at java.desktop/java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:101)
	at java.desktop/java.awt.EventDispatchThread.run(EventDispatchThread.java:90)
Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException: Cannot invoke "String.equals(Object)" because the return value of "java.awt.MenuItem.getLabel()" is null
	at com.dustinredmond.fxtrayicon.FXTrayIcon.isNotUnique(FXTrayIcon.java:1434)
	at com.dustinredmond.fxtrayicon.FXTrayIcon.addMenuItemPrivately(FXTrayIcon.java:989)
	at com.dustinredmond.fxtrayicon.FXTrayIcon.lambda$addMenuItem$9(FXTrayIcon.java:966)
	at java.desktop/java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:318)
	at java.desktop/java.awt.EventQueue.dispatchEventImpl(EventQueue.java:771)
	at java.desktop/java.awt.EventQueue$4.run(EventQueue.java:722)
	at java.desktop/java.awt.EventQueue$4.run(EventQueue.java:716)
	at java.base/java.security.AccessController.doPrivileged(AccessController.java:399)
	at java.base/java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:86)
	at java.desktop/java.awt.EventQueue.dispatchEvent(EventQueue.java:741)
	at java.desktop/java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:203)
	at java.desktop/java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:124)
	at java.desktop/java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:113)
	at java.desktop/java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:109)
	at java.desktop/java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:101)
	at java.desktop/java.awt.EventDispatchThread.run(EventDispatchThread.java:90)
Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException: Cannot invoke "String.equals(Object)" because the return value of "java.awt.MenuItem.getLabel()" is null
	at com.dustinredmond.fxtrayicon.FXTrayIcon.isNotUnique(FXTrayIcon.java:1434)
	at com.dustinredmond.fxtrayicon.FXTrayIcon.addMenuItemPrivately(FXTrayIcon.java:989)
	at com.dustinredmond.fxtrayicon.FXTrayIcon.lambda$addMenuItem$9(FXTrayIcon.java:966)
	at java.desktop/java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:318)
	at java.desktop/java.awt.EventQueue.dispatchEventImpl(EventQueue.java:771)
	at java.desktop/java.awt.EventQueue$4.run(EventQueue.java:722)
	at java.desktop/java.awt.EventQueue$4.run(EventQueue.java:716)
	at java.base/java.security.AccessController.doPrivileged(AccessController.java:399)
	at java.base/java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:86)
	at java.desktop/java.awt.EventQueue.dispatchEvent(EventQueue.java:741)
	at java.desktop/java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:203)
	at java.desktop/java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:124)
	at java.desktop/java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:113)
	at java.desktop/java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:109)
	at java.desktop/java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:101)
	at java.desktop/java.awt.EventDispatchThread.run(EventDispatchThread.java:90)

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

here is my mac os info:
image

hope that I have described clear

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?

Icon looks blurred over time

Another issue I'm facing is this:

It looks OK at the start:

image

But after a while (maybe after a few hours, I don't know exactly), it looks like this or even worse sometimes:

image

I tried saving my icon both as .gif and .png. Neither worked.

JFXCentral Badge

Would be great if you could add this badge to your readme:

[![JFXCentral](https://img.shields.io/badge/Find_me_on-JFXCentral-blue?logo=googlechrome&logoColor=white)](https://www.jfx-central.com/libraries/fxtrayicon)

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)

Support for RadioMenuItems

It would be very nice to have support for CheckMenuItem and RadioMenuItem to allow users to toggle select in the tray icon menu.

Write basic unit tests (non-visual, no GUI)

Writing tests for JavaFX applications, or GUI applications in general isn't much fun. It's quite hard to automate. Especially in a headless build environment. There are some great projects out there for it, but this Issue is centered around the non-GUI aspects of the library, and would be great for first time contributors.

All of that being said, FXTrayIcon lacks basic unit tests, if we call the show() method, we should check that an instance of fxTrayIcon.isShowing() returns true and the like.

I've been rather busy with work lately and my open source projects have seen the neglect associated with that. If anyone who uses/knows/loves FXTrayIcon could contribute some of these unit tests, I would be eternally grateful. It's fairly easy work, I just lack the time right now, and the folks who use the library should be able to have confidence that it will continue to be supported and improved.

I would also ask that if you've contributed to open source before, please leave this for someone else.

Many thanks,

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?

After adding menu items, Actions listener on menu items not working

Hi! If I first set actions before actual adding item, it's working as expected. But if first add item and then add event / action then it's not working fine.

As shown, it's not working, as setOnAction() is used after adding menu item e.g. addMenuItem()

MenuItem menuItemTest = new MenuItem("Create some JavaFX component!");
trayIcon.addMenuItem(menuItemTest);

menuItemTest.setOnAction(e ->
   new Alert(Alert.AlertType.INFORMATION, "We just ran some JavaFX code from an AWT MenuItem!").showAndWait()
);

In simple awt codding both cases are working fine!

Menus / folders always at the bottom

Is there a reason why menus are always placed at the bottom of the menu. I now have a menu with four to five menu items, then the "exit" item, then the menus with subitems. How can I get the exit item to be all the way at the bottom?

How to remove tray icon after showing message

I'm trying to remove tray icon after showing message using this code :

private void showNotification(String title, String message, MessageType type) {
        if (FXTrayIcon.isSupported()) {
            FXTrayIcon notification = new FXTrayIcon((Stage) container.getScene().getWindow(), DownloaderUIController.class.getResource("icons/icon.png"));
            notification.show();
            switch (type) {
                case INFO -> notification.showInfoMessage(title, message);
                case WARNING -> notification.showWarningMessage(title, message);
                case ERROR -> notification.showErrorMessage(title, message);
            }
            notification.clear();
        }
    }

    private enum MessageType {
        INFO, WARNING, ERROR
    }

but there is still
also I'm using windows 10

How to set Taskbar icon to JFXFileChooser?

As Javafx File Chooser have no icon (but in swing icon can be set). So how can icon be changed or hide from taskbar?

Javafx File Chooser show icon of java at taskbar which is boaring...

Icon Size Discussion

Hi Dustin,

I thought it might be best to have this discussion on an issue.

(I know this seems like a lot of words for such a simple thing, but being thorough never ruined anything)

As I was contemplating whether or not to include the ability to define icon size as an argument in the animation feature, I looked over the code everywhere a reference to icon size happens and a couple of things occurred to me:

1 - I think after having much discussion concerning icon size -as has been the case in different issues - it seems to be a constant that Windows likes one size while MACs like a different size but that once those sizes are used, decreasing the size only makes the icon look bad and increasing the size beyond that sweet spot - at least on a mac - has no effect at all.

2 - So then does it make sense to work towards removing the option of sizing the icon at all?

As I thought that through; what made the most sense to me, would be to work towards removing size options altogether, while allowing someone to change the size one time and have that change remain constant - which fits Builder style quite well but could also be worked into traditional class constructors.

So in that line of thinking, I would like to deprecate all constructors and methods that accept the sizing of the icon as arguments ... with the eventual complete removal of that code after some time has passed.

This is how I would implement it in the code:

I would use a class - preferably a record class, but those don't exist in Java 11 which is I believe what you publish the library in ... The class will only have two integer variables for width and height. Then, one instance of that class (call it iconScale) where the values for W and H are set based on the running operating system.

Then, whenever a call is made to a method that does not require icon dimensions to be specified, the values in iconScale will be used.

Then, we use the method setIconSize that will give people the option of overriding the values in iconScale - where I tend to lean into having that as a separate method as well as a Builder option but not massaging it into the formal constructors.

Then deprecate all methods and constructors that accept size values and change the Javadocs explaining what the plan is and encouraging the use of the non-deprecated code.

Public methods that accept dimensions as an argument will continue to call the related private methods that use those values, while the public methods that don't take those values result in the related private methods using the values from iconScale.

With everything in place like that, once we pull the trigger on removing the deprecated code, we will only need to delete the code without making any other changes and everything will continue to work under the new model.

I see two major advantages to transitioning over to this model:

1 - The code becomes much simpler because icon size is now relegated to one single object and that object is only referenced in a small number of methods where the only public-facing method would be in setIconSize and nowhere else.

2 - Library usability becomes much simpler requiring less thought to use it (gee what size should I make these icons to meet the requirements of the constructors and methods?), where under the new model no one need be concerned about it ... this also declutters (a little bit) the code that uses the library.

If you like the plan, I'll submit the PR right away and make all of the Javadoc changes as well as describe the plan in the README.

I tend to think that the only way this could ever be problematic for users of the library - would be in those cases where they miss the version upgrade that has the marked deprecations and they end up going straight to the version that has that code removed which would then break their code completely, though it would be a relatively easy fix for them, it would be the only scenario where someone could be caught off guard. But if we let the deprecated code stay in for like six months or so, I think most people would see the deprecation and make adjustments accordingly before pulling the final trigger on the new model.

Overall, the notion of simplifying any library is of course the holy grail of writing such code. This scenario is certainly minor ... but still relevant I think.

Your thoughts on this?

Text instead of icon

Hi there,

Just a short question/feature request...would it be possible to have a text in the tray icon instead of an icon? Would be nice to have the ability to set/change text in the system tray.

Show Popup Menu with left click

Hi,

Currently, the tray icon shows the menu only when right-clicked. How can we change this behavior so that it does the same with a left click.

Thanks

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

addMenuItem after tray is shown throws exception

var tray = new FXTrayIcon(primaryStage, ...);
tray.show();
tray.addExitItem("Exit");
tray.addMenuItem(new MenuItem("Item"));

throws

Exception in thread "AWT-EventQueue-0" java.lang.IllegalArgumentException: index less than zero.
	at java.desktop/java.awt.Menu.insert(Menu.java:323)
	at [email protected]/com.dustinredmond.fxtrayicon.FXTrayIcon.addMenuItemPrivately(FXTrayIcon.java:998)
	at [email protected]/com.dustinredmond.fxtrayicon.FXTrayIcon.lambda$addMenuItem$9(FXTrayIcon.java:970)

Feature Request: Make getTrayIcon() public

Currently there is no simple way to get the underlying java.awt.TrayIcon. As such you cannot do essential things such as checking if a user right clicked the tray icon.

As a workaround, you can inherit from FXTrayIcon and expose getTrayIcon with a different function name.

When another thread is running, some codding stops working!

For example, I am using this code:

MenuItem mnuSoftVersionStatus = new MenuItem(SOFT_VERSION);
trayIcon.addMenuItem(mnuSoftVersionStatus);

mnuSoftVersionStatus.setText(SOFT_VERSION + " : " + "Starting");
new org.hsqldb.Server().start();
mnuSoftVersionStatus.setText(SOFT_VERSION + " : " + "Running");

After this new org.hsqldb.Server().start(); the mnuSoftVersionStatus.setText() is not working?

FXtrayIcon error when used it with springboot fx application

When I'm using FXTrayIcon with JavaFX application that's work fine but now I need to run my project as spring-boot fx project
I follow instructions here to run the spring-boot project as FX project
https://blog.jetbrains.com/idea/2019/11/tutorial-reactive-spring-boot-a-javafx-spring-boot-application/

but when I used FXTrayIcon get me this exception message

Exception in Application start method
Exception in thread "main" java.lang.RuntimeException: Exception in Application start method
	at com.sun.javafx.application.LauncherImpl.launchApplication1(LauncherImpl.java:901)
	at com.sun.javafx.application.LauncherImpl.lambda$launchApplication$2(LauncherImpl.java:196)
	at java.base/java.lang.Thread.run(Thread.java:831)
Caused by: java.awt.HeadlessException
	at java.desktop/java.awt.GraphicsEnvironment.checkHeadless(GraphicsEnvironment.java:165)
	at java.desktop/java.awt.MenuComponent.<init>(MenuComponent.java:181)
	at java.desktop/java.awt.MenuItem.<init>(MenuItem.java:224)
	at java.desktop/java.awt.MenuItem.<init>(MenuItem.java:208)
	at java.desktop/java.awt.Menu.<init>(Menu.java:163)
	at java.desktop/java.awt.Menu.<init>(Menu.java:144)
	at java.desktop/java.awt.PopupMenu.<init>(PopupMenu.java:88)
	at java.desktop/java.awt.PopupMenu.<init>(PopupMenu.java:75)
	at com.dustinredmond.fxtrayicon.FXTrayIcon.<init>(FXTrayIcon.java:885)
	at com.dustinredmond.fxtrayicon.FXTrayIcon.<init>(FXTrayIcon.java:84)
	at com.dustinredmond.fxtrayicon.FXTrayIcon$Builder.<init>(FXTrayIcon.java:153)
	at com.ahmedsr.alphasyncui.AlphaSyncApplication.start(AlphaSyncApplication.java:29)
	at com.sun.javafx.application.LauncherImpl.lambda$launchApplication1$9(LauncherImpl.java:847)
	at com.sun.javafx.application.PlatformImpl.lambda$runAndWait$12(PlatformImpl.java:484)
	at com.sun.javafx.application.PlatformImpl.lambda$runLater$10(PlatformImpl.java:457)
	at java.base/java.security.AccessController.doPrivileged(AccessController.java:391)
	at com.sun.javafx.application.PlatformImpl.lambda$runLater$11(PlatformImpl.java:456)
	at com.sun.glass.ui.InvokeLaterDispatcher$Future.run$$$capture(InvokeLaterDispatcher.java:96)
	at com.sun.glass.ui.InvokeLaterDispatcher$Future.run(InvokeLaterDispatcher.java)
	at com.sun.glass.ui.win.WinApplication._runLoop(Native Method)
	at com.sun.glass.ui.win.WinApplication.lambda$runLoop$3(WinApplication.java:184)
	... 1 more

I ask about what's capabilities to integrate fxtrayicon with spring-boot-fx

Tray icon is non-transparent on some Linux desktop environments

I have tested my application xpipe on various Linux distros and noticed that the tray icon it looks off on some of them. Here is for example how it looks on manjaro with Plasma and KWin (the default Manjaro ones):

image

On any other operating system or DEs like gnome it looks fine.

For reference, this is the code I use to call FXTrayIcon: https://github.com/xpipe-io/xpipex/blob/d2ac3383ac0b6202f567f42b963819f10b0c98c8/app/src/main/java/io/xpipe/app/core/AppTray.java

Write unit tests for FXTrayIcon class

As the creator of FXTrayIcon, I have a good deal of experience writing both JavaFX and writing unit tests, however, I do not have a lot of experience writing test cases for GUI software. I'm more the type of person that writes->compiles->clicks about->finds bug->repeat when it comes to JavaFX and Swing development.

FXTrayIcon has a "runnable test" that serves as a basic smoke/sanity test, but the project would benefit from well-written tests.
Currently, the build system really only checks if the code compiles, but it would be nice to see a passed build as a sign that they API actually does what it is intended to do.

I'm going to leave this issue open in hopes that someone who is experienced in writing tests for JavaFX and Swing will have a go.

No system tray support, application exiting.

I tested on windows 10 vmware and ubuntu 18.xx and have this message.
1)Do you know how many windows 10 have system tray return true?
2)it can be possible implement for java desktop on c++ when it returns false?

Icon resolution limited to 16x16 on Windows

Hi,

I am unable to obtain a higher resolution than 16x16 for the tray icon on Windows, which makes it appear very low res compared to other icons on Windows 10.

After a bit of searching I tried a suggestion hinted on a Stack Overflow comment here, suggesting to turn on auto size using setAutoImageSize, otherwise the Windows implementation of AWT TrayIcon targets 16x16. This suggestion actually worked so I'm sharing the concept code below. Think it would be great if functionality to enable higher res icons could be incorporated into the main library by default.

// Code for default res (results in 16x16 icon even though source image is more than 600 pixels wide and high)
// Varying this code to explicitly pass the width and height does not change the result
FXTrayIcon trayIcon = new FXTrayIcon(stage, FXTrayIcon.class.getResource("FXIconRedWhite.png"));

Resulting icon from above code on Windows 10:
Default res

// High res (32x32)
FXTrayIcon2 trayIcon = new FXTrayIcon2(stage, FXTrayIcon.class.getResource("FXIconRedWhite.png"),32,32);


/** @file FXTrayIcon2.java */
import com.dustinredmond.fxtrayicon.FXTrayIcon;
import javafx.stage.Stage;
import java.net.URL;

public class FXTrayIcon2 extends FXTrayIcon {
    // Per hint on https://stackoverflow.com/questions/10820255/java-awt-systemtray-does-not-display-tray-icon-properly
    // Windows implementation of TrayIcon targets 16x16 size if you do not specify autosize on
    public FXTrayIcon2(Stage parentStage, URL iconImagePath, int width, int height) {
        super(parentStage, iconImagePath, width, height);
        super.trayIcon.setImageAutoSize(true);
    }
}

Resulting icon from above code on Windows 10 (higher resolution attained):
High res

Doesn't work under Fedora 35 (GNOME 41)

Hi,

The instance of FXTrayIcon silently blocking at his creation.
it seems to be because of GTK (4).

Thanks for your work: I hope this library will become fully functional soon.

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.

MenuItem order wrong for .addExitMenuItem()

When building a Tray Icon using the Builder API and adding .addExitMenuItem() the exit menu item shows up on top of the list.

Check:

FXTrayIcon trayIcon =
            new FXTrayIcon.Builder(stage, resource).menuItem("Settings",
                    e-> myMethod()).separator().menuItem(item).addExitMenuItem().show().build();

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

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

Ubuntu 20.04 UnsupportedOperationException: SystemTray icons are not supported

Hi there,

I am about to use FXTrayIcon but facing the issue, that I am getting the Exception

java.lang.UnsupportedOperationException: SystemTray icons are not supported by the current desktop environment.

I got the point, that Gnome removed the SystemTray strangely, and I need to install but the system tray is sadly still not working.
So not clear if a package is still missing.

I have already had installed

sudo apt install gnome-shell-extension-appindicator

And I have icons in the tray like skype, shutter, Dropbox VLC and so on.

I am willing to support here, to get a fix about this issue. Require only more "directions" how to support, to get SystemTray icons working on Ubuntu
Afaik this is the same case #12

package com.dustinredmond does not exist

Hello,

try to use your package.
My gradle looks like this:

// Mustercode für build.gradle
plugins {
    id 'java'
    // add
    id 'application'
    id 'org.openjfx.javafxplugin' version '0.0.8'
}

// add
mainClassName = 'org.stingle.photos.MainApp'

sourceCompatibility = 1.8

repositories {
    mavenCentral()
}

dependencies {
    compile group: 'com.dustinredmond.fxtrayicon', name: 'FXTrayIcon', version: '2.6.0'
    testCompile group: 'junit', name: 'junit', version: '4.12'
}

// add
javafx {
    version = "11"
    modules = [ 'javafx.controls', 'javafx.fxml' ]
}

My class looks like this:

package org.stingle.photos;

import javafx.application.*;
import javafx.fxml.FXMLLoader;
import javafx.scene.*;
import javafx.stage.*;
import com.dustinredmond.fxtrayicon;

import java.io.IOException;

public class MainApp extends Application {
    public static void main(String[] args) {
        launch(args);
    }

    @Override
    public void start(Stage primaryStage) {
        try {
            Parent root = FXMLLoader.load(getClass().getResource("/login.fxml"));
            Scene scene = new Scene(root, 350, 500);
            primaryStage.setTitle("Stingle Photos");
            primaryStage.setScene(scene);
            primaryStage.setResizable(false);
            primaryStage.show();

            FXTrayIcon icon = new FXTrayIcon(primaryStage, getClass().getResource("/images/logo.png"));
            icon.show();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}

I get these errors when I run gradle

~/Entwicklung/org.stingle.photos via ☕ v15.0.2 ❯ ./gradlew run

> Task :compileJava FAILED
/Users/maltekiefer/Entwicklung/org.stingle.photos/src/main/java/org/stingle/photos/MainApp.java:7: error: package com.dustinredmond does not exist
import com.dustinredmond.fxtrayicon;
                        ^
/Users/maltekiefer/Entwicklung/org.stingle.photos/src/main/java/org/stingle/photos/MainApp.java:26: error: cannot find symbol
            FXTrayIcon icon = new FXTrayIcon(primaryStage, getClass().getResource("/images/logo.png"));
            ^
  symbol:   class FXTrayIcon
  location: class MainApp
/Users/maltekiefer/Entwicklung/org.stingle.photos/src/main/java/org/stingle/photos/MainApp.java:26: error: cannot find symbol
            FXTrayIcon icon = new FXTrayIcon(primaryStage, getClass().getResource("/images/logo.png"));
                                  ^
  symbol:   class FXTrayIcon
  location: class MainApp
3 errors

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':compileJava'.
> Compilation failed; see the compiler error output for details.

* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.

* Get more help at https://help.gradle.org

Deprecated Gradle features were used in this build, making it incompatible with Gradle 7.0.
Use '--warning-mode all' to show the individual deprecation warnings.
See https://docs.gradle.org/6.7/userguide/command_line_interface.html#sec:command_line_warnings

BUILD FAILED in 753ms
1 actionable task: 1 executed

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?

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.

showMessage() title of the notification window

Hi.
All showMessage() methods implemented in this project displays a notification message of different types (info, warning, error..).
But the title of that notification is "OpenJDK Platform binary" which is not a good idea to show it, it's annoing. I want to change it to my app's name.
How can we change that title?

Title

Icon looks distorted

My icon is 16x16. SystemTray.getSystemTray().getTrayIconSize() returns java.awt.Dimension[width=16,height=16] as well. But sometimes the icon looks distorted as in the image:

image

How can I fix that? Have you guys faces a similar issue?

Blurry Icon with FXTrayIcon, Clearer Icon with AWT

Hi Dustin

image

I would like to report an issue regarding the tray icon display. The icon set using FXTrayIcon on the left appears to be blurry, while the system icon set using AWT on the right looks clearer. This inconsistency in the icon quality is affecting the overall user experience. It would be greatly appreciated if this issue could be addressed and the clarity of the FXTrayIcon icon improved to match the quality of the AWT system icon.

Thank you for your attention to this matter.

  • OS: windows10
  • Image:
    tray-icon2-windows
  • Code
        if (OSUtil.isWindows()) {
            Dimension trayIconSize = new Dimension(16, 16);
            if (FXTrayIcon.isSupported()) {
                 trayIconSize = SystemTray.getSystemTray().getTrayIconSize();
            }

            java.awt.Image image = null;
            try {
                URL url = getClass().getResource("tray-icon2-windows.png");
                assert url != null;
                image = ImageIO.read(url);
            } catch (IOException ex) {
                System.out.println(ex);
            }
            assert image != null;

            trayIcon = new FXTrayIcon(stage);
            trayIcon.setGraphic(image.getScaledInstance(trayIconSize.width, trayIconSize.height, Image.SCALE_SMOOTH));
            //trayIcon.setGraphic(new javafx.scene.image.Image(Objects.requireNonNull(JFXCentral2App.class.getResource("tray-icon2-windows.png")).toExternalForm(), trayIconSize.width, trayIconSize.height, true, true));
        }else {
            trayIcon = new FXTrayIcon(stage, Objects.requireNonNull(JFXCentral2App.class.getResource("tray-icon2.png")), 350, 210);
        }

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.