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

Multiple Accelerators don't work as expected

    XMLWordPrintable

Details

    • Bug
    • Resolution: Unresolved
    • P4
    • tbd
    • 8u40
    • javafx
    • Linux

    Description

      import javafx.application.Application;
      import javafx.scene.Scene;
      import javafx.scene.control.ContextMenu;
      import javafx.scene.control.MenuItem;
      import javafx.scene.control.TextArea;
      import javafx.scene.input.KeyCombination;
      import javafx.scene.layout.VBox;
      import javafx.stage.Stage;

      public class AcceleratorTest extends Application {

      public void start(Stage primaryStage) {
      TextArea ta1 = new TextArea();
      TextArea ta2 = new TextArea();

      MenuItem item1 = new MenuItem("Insert \"Hello\"");
      item1.setOnAction((ActionEvent) -> ta1.setText("Hello"));
      item1.setAccelerator(KeyCombination.keyCombination("Ctrl+I"));

      MenuItem item2 = new MenuItem("Insert \"World!\"");
      item2.setOnAction((ActionEvent) -> ta2.setText("World!"));
      item2.setAccelerator(KeyCombination.keyCombination("Ctrl+I"));

      ContextMenu context1 = new ContextMenu();
      context1.getItems().add(item1);

      ContextMenu context2 = new ContextMenu();
      context2.getItems().add(item2);

      ta1.setContextMenu(context1);
      ta2.setContextMenu(context2);

      VBox vBox = new VBox();
      vBox.getChildren().add(ta1);
      vBox.getChildren().add(ta2);

      Scene scene = new Scene(vBox, 300, 300);

      primaryStage.setTitle("Accelerator Test");
      primaryStage.setScene(scene);
      primaryStage.show();
      }

      public static void main(String[] args) {
      launch(args);
      }

      }

      If you start this application, but the text cursor into the first TextArea and press Ctrl+I, the text of the second textarea is set.

      This is quite unexpected, as the shortcuts live within a contextmenu of their respective textareas.

      I think the current situation of not supporting the same accelerator to execute different actions is suboptimal.

      Attachments

        Activity

          People

            Unassigned Unassigned
            rlichtenbjfx Robert Lichtenberger (Inactive)
            Votes:
            1 Vote for this issue
            Watchers:
            4 Start watching this issue

            Dates

              Created:
              Updated:
              Imported: