-
Bug
-
Resolution: Not an Issue
-
P3
-
None
-
jfx11, 8, jfx17, jfx21, jfx22
-
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`.
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`.
- relates to
-
JDK-8114638 ContextMenu does not go away on mouse down in the context menu control
- Closed