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

Menu accelerator does not work if menu item has been added dynamically

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Fixed
    • Icon: P3 P3
    • 8u40
    • 8u25
    • javafx
    • None
    • Win 7 Java 8u25

      Menu accelerator does not work if menu item has been added dynamically, thus, after the stage is shown. I would expect that every time menu item is visible and enabled that it's accelerator will work as well.

      Next code snippet can reproduce the issue.

      @Override
      public void start(Stage stage) throws Exception {
      MenuBar menuBar = new MenuBar();
      Menu menu = new Menu("Menu");
      menuBar.getMenus().addAll(menu);

      VBox root = new VBox();
      root.getChildren().add(menuBar);
      stage.setTitle("Test");
      stage.setScene(new Scene(root, 300, 275));
      stage.show();

      MenuItem menuItem = new MenuItem("Menu A");
      menuItem.setAccelerator(KeyCombination.keyCombination("Ctrl+A"));
      menuItem.setOnAction(event -> System.out.println("Menu A is selected"));
      menu.getItems().add(menuItem);
      }

            jgiles Jonathan Giles
            vspasojevjfx Vitomir Spasojevic (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported: