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

Menu is disappearing on click even when having Menu items in it

XMLWordPrintable

      Run this sample program:
      "

      import javafx.application.Application;
      import javafx.event.ActionEvent;
      import javafx.scene.Scene;
      import javafx.scene.control.Button;
      import javafx.scene.control.Menu;
      import javafx.scene.control.MenuBar;
      import javafx.scene.control.MenuItem;
      import javafx.scene.layout.BorderPane;
      import javafx.stage.Stage;

      public class MenuButtontest extends Application {

          public static void main(String[] args) {
              Application.launch(MenuButtontest.class, args);
          }

          @Override
          public void start(Stage stage) {

              MenuBar bar = new MenuBar();

              Button button = new Button("add menu");

              addMenu(bar);

              button.setOnAction((ActionEvent event) -> {
                  addMenu(bar);
              });
              BorderPane pane = new BorderPane(button);
              pane.setTop(bar);
              Scene scene = new Scene(pane);
              stage.setScene(scene);
              stage.show();
          }

          private void addMenu(MenuBar bar) {
              Menu menu = new Menu("test");
              bar.getMenus().add(menu);

              MenuItem item = new MenuItem("Menu item");
              item.setOnAction((ActionEvent event) -> {
                  System.out.println("TEST");
              });

              Menu menu2 = new Menu("menu two");
              menu.getItems().add(menu2);
              menu2.getItems().add(item);
          }
      }
      "
      Click on the "test" Menu in the menuBar. Then click on "menu two" that has appeared. Nothing is happening apart from the "Menu Item" appearing. Clicking on the Menu does nothing, it's normal.

      Now click on "add menu" button which add the exact same Menu next to the previous.

      Now do the exact pattern on the second Menu. You will see that clicking on the "menu two" will make the whole menu disappear.

      So we have a difference in behavior between two exact Menus.
      Any thought?

            jgiles Jonathan Giles
            shadzic Samir Hadzic
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported: