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

ContextMenu: accelerators not working without access to hidden api



      Happens if the contextMenu is shown directly in onContextMenuRequested (vs control.setContextMenu - which isn't available for Nodes that are not of type Control anyway).

      To reproduce, compile and run the example below
      - press F9
      - expected: log message printed
      - actual: nothing

      To make it work, uncomment the access to hidden api. Actually, even this need for additional registration is unexpected - would expect accelerators to "just work" when set on a MenuItem.

      In RL it's critical f.i. in contextMenus of TableHeader: see http://stackoverflow.com/q/39721544/203657

      import java.util.logging.Logger;

      import com.sun.javafx.scene.control.ControlAcceleratorSupport;

      //import de.swingempire.fx.util.FXUtils;
      import javafx.application.Application;
      import javafx.scene.Parent;
      import javafx.scene.Scene;
      import javafx.scene.control.ContextMenu;
      import javafx.scene.control.MenuItem;
      import javafx.scene.input.KeyCombination;
      import javafx.scene.layout.BorderPane;
      import javafx.scene.shape.Circle;
      import javafx.scene.shape.Shape;
      import javafx.stage.Stage;

       * @author Jeanette Winzenburg, Berlin
      public class BugAcceleratorNotNode extends Application {

          private Parent getContent() {
              ContextMenu circleMenu = new ContextMenu();
              MenuItem circleItem = new MenuItem("in Circle");
              circleItem.setOnAction(e -> LOG.info("action in Circle"));
              Shape circle = new Circle(200);
              circle.setOnContextMenuRequested(e -> {
                  LOG.info("requested: " + e);
                  circleMenu.show(circle, e.getScreenX(), e.getScreenY());
              // uncomment to make accelerator work
              //ControlAcceleratorSupport.addAcceleratorsIntoScene(circleMenu.getItems(), circle);

              BorderPane pane = new BorderPane(circle);
              return pane;

          public void start(Stage primaryStage) throws Exception {
              primaryStage.setScene(new Scene(getContent(), 600, 400));
        // primaryStage.setTitle(FXUtils.version());

          public static void main(String[] args) {
          private static final Logger LOG = Logger





            • Assignee:
              aghaisas Ajit Ghaisas
              fastegal Jeanette Winzenburg
            • Votes:
              0 Vote for this issue
              2 Start watching this issue


              • Created: