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

[mac] Action attached to a menu item is called many times when using the corresponding accelerator if KeyCharacterCombination is used

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Duplicate
    • Icon: P4 P4
    • 7-pool
    • fx2.0.2
    • javafx
    • FX 2.0.2 promoted b03
      macos

      On Mac if I set an accelerator on a MenuItem that defines a modifier, say ctrl + a, and if I do so using KeyCharacterCombination, as soon as I press the modifier key the handler attached to the action defined for this menu entry is called many times.
      That means, as of the code extract below, I see many output lines "menuitem1 got Event" even before I have time to press "a" key.
      I should see this output only once and when both ctrl and "a" keys are pressed. At least this is the behavior I get on Windows.
      For some reason when using KeyCodeCombination it does as expected on both Mac and Windows.

      // KeyCodeCombination acceleratorKeyComboA =
      // new KeyCodeCombination(KeyCode.A,
      // KeyCombination.CONTROL_DOWN);
              KeyCharacterCombination acceleratorKeyComboA =
                      new KeyCharacterCombination("a",
                                             KeyCombination.CONTROL_DOWN);

              MenuItem menuitem1 = new MenuItem();
              menuitem1.setText("_Open");
              menuitem1.setMnemonicParsing(true);
              menuitem1.setAccelerator((KeyCombination) acceleratorKeyComboA);
              menuitem1.setOnAction(new EventHandler<ActionEvent>() {
                  @Override public void handle(ActionEvent e) {
                      System.out.println("menuitem1 got Event: " + e);
                  }
              });

            miflemi Mick Fleming
            yjoan Yves Joan (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported: