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

Cannot get owner node of ContextMenu

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Not an Issue
    • Icon: P3 P3
    • None
    • jfx11, 8, jfx17, jfx21, jfx22
    • javafx
    • generic
    • generic

      A DESCRIPTION OF THE PROBLEM :
      I want to get owner node of ContextMenu (call `ContextMenu.getOwnerNode`) but the result is null, like this:
      ```
      public class App extends Application {
          @Override
          public void start(Stage primaryStage) throws Exception {
              MenuItem menuItem = new MenuItem("Click me");
              menuItem.setOnAction(event -> {
                  String text = menuItem.getParentPopup().getOwnerNode() != null ? "Owner node is not null" : "Owner node is null";
                  new Alert(Alert.AlertType.INFORMATION, text).showAndWait();
              });

              ContextMenu contextMenu = new ContextMenu(menuItem);

              Button button = new Button("Right click me");
              button.setContextMenu(contextMenu);

              primaryStage.setScene(new Scene(new BorderPane(button)));
              primaryStage.show();
          }
      }
      ```

      Set breakpoint in `ContextMenu.doShow`, `anchor` parameter is not null. The reason is that when ContextMenu is set to Control (call `Control.setContextMenu`), `ContextMenu.isShowRelativeToWindow` is true, it only set `ownerWindow` and not set `ownerNode`.


        1. App.java
          1.0 kB
        2. Capture.PNG
          Capture.PNG
          18 kB

            angorya Andy Goryachev
            webbuggrp Webbug Group
            Votes:
            0 Vote for this issue
            Watchers:
            5 Start watching this issue

              Created:
              Updated:
              Resolved: