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

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

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Resolved
    • Priority: P3
    • Resolution: Fixed
    • Affects Version/s: 8u25
    • Fix Version/s: 8u40
    • Component/s: javafx
    • Labels:
      None
    • Environment:

      Win 7 Java 8u25

      Description

      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);
      }

        Attachments

          Activity

            People

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

              Dates

              Created:
              Updated:
              Resolved:
              Imported: