Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

A bug? Or am I doing something wrong? #57

Closed
KaitlynEthylia opened this issue Jul 10, 2022 · 7 comments
Closed

A bug? Or am I doing something wrong? #57

KaitlynEthylia opened this issue Jul 10, 2022 · 7 comments

Comments

@KaitlynEthylia
Copy link

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```
@EasyG0ing1
Copy link
Contributor

@KacyBiscuit

Try using the Builder class of FXTrayIcon, like this:

Menu dictionary = new Menu("Dictionary");
dictionary.getItems().addAll(customDictionary, saveDictionary, loadDictionary, editDictionary);

FXTrayIcon trayIcon = new FXTrayIcon.Builder(parentStage, iconFile, width, height)
  .menuItem(saveSettings)
  .menuItem(loadSettings)
  .separator()
  .menuItem(keyListener)
  .menuItem(paused)
  .menu(dictionary)
  .separator()
  .menuItem(show)
  .menuItem(hide)
  .addExitMenuItem("Exit")
  .show()
  .build();

It should put everything in the order that you have them placed in your build sentence.

Also, when you add any item to an existing FXTrayIcon, the library will verify that the label String assigned to the item does not already exist in the trayMenu, and if it does, it will throw an error.

@EasyG0ing1
Copy link
Contributor

@KacyBiscuit - It's been a while since you opened this incident, have the comments I made been of any use to you?

@KaitlynEthylia
Copy link
Author

So sorry for the long reply! I had thought I'd replied before but I must've forgot as I've been busy recently, that helped greatly thanks! although I don't entirely understand the second part of your message as when I'm adding them they definately don't already exist so I don't see why it should throw an error

@EasyG0ing1
Copy link
Contributor

So sorry for the long reply! I had thought I'd replied before but I must've forgot as I've been busy recently, that helped greatly thanks! although I don't entirely understand the second part of your message as when I'm adding them they definately don't already exist so I don't see why it should throw an error

What I mean by saying "when you add any item to an existing FXTrayIcon" - I'm talking about after you have already created an instance of FXTrayIcon, and then you add menuItems into it (as opposed to adding all of your menuItems in your build sentence).

The only point I was trying to make, is that FXTrayIcon checks the label of every menuItem that you place into FXTrayIcon, and if it sees that the words in the label have already been used, then it will throw an error.

This example should make it clearer:

Let's say that I create a new instance of FXTI

FXTrayIcon trayIcon = new FXTrayIcon.Builder(stage, iconImage, imageWidth, imageHeight)
     .menuItem("Open File", e-> openFile())
     .menuItem("Close File", e-> closeFile())
     .separator()
     .addExitMenuItem("Exit", e-> closeProgram())
     .show();

Then after that object is already created, I then try to do something like this:

MenuItem openFile = new MenuItem("Open File");
openFile.setOnAction(e -> openFile());
trayIcon.addMenuItem(openFile);

FXTrayIcon will throw an error because it already has a menuItem with the label "Open File" in it.

Does that make sense?

I wasn't saying necessarily that you were trying to do this, I was just pointing out that if you were, then you would get an error ... that's all I was saying.

@dustinkredmond
Copy link
Owner

Has this issue been resolved?

@KaitlynEthylia
Copy link
Author

so sorry, it has been but ive been logged out of github for a while so i havnt been receaving notifications

@ctoabidmaqbool
Copy link

best of luck!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants