dustinkredmond / FXTrayIcon

Tray Icon implementation for JavaFX applications. Say goodbye to using AWT's SystemTray icon, instead use a JavaFX Tray Icon.
MIT License
324 stars 25 forks source link

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

Closed ctoabidmaqbool closed 1 year ago

ctoabidmaqbool commented 1 year ago

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!

dustinkredmond commented 1 year ago

I'm not sure there's a property that we can listen for in JavaFX to tell when action listeners are added/removed after they've already been added to the FXTrayIcon. I will check for this, then update.

dustinkredmond commented 1 year ago

After looking through the API, I'm not sure how this can be handled without some mild sorcery (or a ton or Reflection). I'm going to close this issue, but will keep this in mind. Please feel free to re-open if you can think of any suggestions to mitigate this unexpected behavior. Thanks for raising the issue!