Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8314034

Fill menu items on showing menu

XMLWordPrintable

    • generic
    • generic

      A DESCRIPTION OF THE PROBLEM :
      I want to fill menu items while menu on showing, like this:
      ```
      public class Main extends FXApplication {

          @Override
          public void start(Stage primaryStage) throws Exception {
              Menu menu = new Menu("Menu");
              menu.setOnShowing(event -> {
                  // Fill menu items.
                  menu.getItems().add(new MenuItem("MenuItem 1"));
              });

              MenuBar menuBar = new MenuBar(menu);

              BorderPane borderPane = new BorderPane();
              borderPane.setTop(menuBar);

              Scene scene = new Scene(borderPane);
              primaryStage.setScene(scene);
              primaryStage.show();
          }
      }
      ```
      But it cannot work. The reason is that `MenuBarSkin.showMenu` check if the menu is empty and decides whether to show the menu. There are two solutions:
      1. Move menu empty check to after the `Menu.ON_SHOWING` or `MenuItem.MENU_VALIDATION_EVENT` event is fired.
      2. Add an event before showing the menu.


            angorya Andy Goryachev
            webbuggrp Webbug Group
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

              Created:
              Updated: