Class MenuItem

java.lang.Object
javafx.scene.control.MenuItem
All Implemented Interfaces:
Styleable, EventTarget
Direct Known Subclasses:
CheckMenuItem, CustomMenuItem, Menu, RadioMenuItem

@IDProperty("id") public class MenuItem extends Object implements EventTarget, Styleable

MenuItem is intended to be used in conjunction with Menu to provide options to users. MenuItem serves as the base class for the bulk of JavaFX menus API. It has a display text property, as well as an optional graphic node that can be set on it. The accelerator property enables accessing the associated action in one keystroke. Also, as with the Button control, by using the setOnAction(javafx.event.EventHandler<javafx.event.ActionEvent>) method, you can have an instance of MenuItem perform any action you wish.

Note: Whilst any size of graphic can be inserted into a MenuItem, the most commonly used size in most applications is 16x16 pixels. This is the recommended graphic dimension to use if you're using the default style provided by JavaFX.

To create a MenuItem is simple:

MenuItem menuItem = new MenuItem("Open");
menuItem.setOnAction(e -> System.out.println("Opening Database Connection..."));
Circle graphic = new Circle(8);
graphic.setFill(Color.GREEN);
menuItem.setGraphic(graphic);

Menu menu = new Menu("File");
menu.getItems().add(menuItem);
MenuBar menuBar = new MenuBar(menu);
Image of the MenuItem control
Since:
JavaFX 2.0
See Also: