To reproduce just click the menu. It will open and then it will close.
public class MenuItemTest extends Application {
@Override
public void start(Stage primaryStage) {
Parent root = createScene();
Scene scene = new Scene(root, 300, 250);
primaryStage.setTitle(VersionInfo.getRuntimeVersion());
primaryStage.setScene(scene);
primaryStage.show();
}
public static void main(String[] args) {
launch(args);
}
private Parent createScene() {
Menu menu = new Menu("Menu");
for (int i = 0; i < 10; i++) {
MenuItem menuItem = new MenuItem("Item - 0x1" + i);
menu.getItems().add(menuItem);
}
MenuBar menuBar = new MenuBar();
menuBar.getMenus().add(menu);
HBox root = new HBox(5);
root.getChildren().add(menuBar);
return root;
}
}
public class MenuItemTest extends Application {
@Override
public void start(Stage primaryStage) {
Parent root = createScene();
Scene scene = new Scene(root, 300, 250);
primaryStage.setTitle(VersionInfo.getRuntimeVersion());
primaryStage.setScene(scene);
primaryStage.show();
}
public static void main(String[] args) {
launch(args);
}
private Parent createScene() {
Menu menu = new Menu("Menu");
for (int i = 0; i < 10; i++) {
MenuItem menuItem = new MenuItem("Item - 0x1" + i);
menu.getItems().add(menuItem);
}
MenuBar menuBar = new MenuBar();
menuBar.getMenus().add(menu);
HBox root = new HBox(5);
root.getChildren().add(menuBar);
return root;
}
}