Menu - nifty-gui/nifty-gui GitHub Wiki
The Menu control represents a popup menu. These kind of menus are usually activated with a click on the secondary mouse button.
Since this control represents a popup menu it is natually created using a popup layer inside Nifty.
Due to the nature of the popup menu you will usually create a special named popup to show the popup menu. This popup is named "niftyPopupMenu" by default. The actual menu control is then a control inside of this popup and you access it with the usual getNiftyControl() method. Once you've the Menu control you can use the Java API of the Menu control to add menu items.
Here is an example on how to create the popup menu and access it's Menu control:
private void createPopup() {
this.popup = nifty.createPopup("niftyPopupMenu");
Menu<ThisReallyCouldBeAnyClassYouWant> popupMenu = popup.findNiftyControl("#menu", Menu.class);
popupMenu.setWidth(new SizeValue("250px")); // this is required and is not happening automatically!
popupMenu.addMenuItem("MenuItem 1", "menu/listen.png", new ThisReallyCouldBeAnyClassYouWant("Something"));
popupMenu.addMenuItemSeparator();
popupMenu.addMenuItem("MenuItem 2", "menu/something.png", new ThisReallyCouldBeAnyClassYouWant("Something Else"));
}
Once you've created and initialized the popup menu you can use the Nifty showPopup() call to show it (Please note that there is a difference between a popup menu and a general popup (layer) inside Nifty. The nifty.showPopup() call is used to show a popup layer and can be used for general purposes. It does not refer to a popupMenu directly! The popup menu described in here only *uses* the popup layer mechanism):
public void showMenu() {
nifty.showPopup(screen, popup.getId(), null);
}
There are currently no parameters for the Menu control supported.
When an menu item is clicked a MenuItemActivatedEvent is being published.
Due to the nature of the popup menu there is no JavaBuilder support.
Due to the nature of the popup menu there is no XML support.