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

Menus / folders always at the bottom #43

Closed dlemmermann closed 2 years ago

dlemmermann commented 2 years ago

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?

dwalluck commented 2 years ago

If you use the addMenuItem(javafx.scene.control.MenuItem) API, it always inserts at the end of the menu item list. But, there is also a insertMenuItem(javafx.scene.control.MenuItem, int) to insert at a menu item at a certain position.

dustinkredmond commented 2 years ago

Closing, considering the comment made by @dwalluck I will consider implementing an index setting for the "Exit" item in future releases, though if you wanted to create your own custom "Exit" item, it simply calls Platform.setImplicitExit(true); Platform.exit();

EasyG0ing1 commented 2 years ago

@dlemmermann - There is already a Builder method for automatically adding an Exit menu to the bottom of the trayIcon - note the .addExitMenuItem() in this build sentence:

trayIcon = new FXTrayIcon.Builder(stage, getClass().getResource("FXIconRedYellow.png"))
        .toolTip("An alternative tooltip!")
        .menuItem(menuItemTest)
        .menuItem(menuOptions)
        .applicationTitle("FXTrayIcon Builder Text")
        .separator()
        .addExitMenuItem()
        .build();

I'm going to add the option of setting the label as desired in my next PR.

dwalluck commented 2 years ago

Maybe he wants additional methods that add a position index parameter, but I guess a builder is meant to only be called once and it adds the menus in called order.

EasyG0ing1 commented 2 years ago

@dwalluck The Builder does add the menuItems in the order that they are inserted into the build sentence. But the exitMenu can be added anywhere in the build sentence and it will always get placed at the bottom of the menu.

I also think that some kind of an indexing structure would be handy, I might start a new issue on that topic to open it up for some discussion as to how that should look from a usability perspective. I've got some ideas but it's always nice to get everyone's input on that kind of thing.