4 Java Module5 Menu
4 Java Module5 Menu
MODULE-5
JavaFX Menu
JavaFX Menu
• JavaFX provides a Menu class to implement
menus.
• Menu is the main component of any application.
• In JavaFX, javafx.scene.control.Menu class
provides all the methods to deal with menus.
• This class needs to be instantiated to create a
Menu.
JavaFX Menu
//creating MenuBar
ManuBar menubar = new MenuBar();
//creating Menu
Menu MenuName = new Menu("Menu Name");
//creating Menu Item
MenuItem MenuItem1 = new MenuItem("Menu Item 1 Name");
//adding Menu Item to the Menu
MenuName.getItems().add(MenuItem1);
//adding Menu to the MenuBar
menubar.getMenus().add(MenuName);
JavaFX Menu
Method Explanation
getItems() returns the items of the menu
hide() hide the menu
show() show the menu
getMenus() The menus to show within this MenuBar.
Gets the value of the property
isUseSystemMenuBar()
useSystemMenuBar
Sets the value of the property
setUseSystemMenuBar(boolean v)
useSystemMenuBar.
setOnHidden(EventHandler v) Sets the value of the property onHidden.
setOnHiding(EventHandler v) Sets the value of the property onHiding.
setOnShowing(EventHandler v) Sets the value of the property onShowing.
setOnShown(EventHandler v Sets the value of the property onShown.
Example