ContextMenuEvent (JavaFX 17)

Module javafx.graphics
Package javafx.scene.input

## Class ContextMenuEvent

- java.lang.Object
- - java.util.EventObject
  - - javafx.event.Event
    - - javafx.scene.input.InputEvent
      - - javafx.scene.input.ContextMenuEvent

- All Implemented Interfaces:
    `Serializable`, `Cloneable`

      public class ContextMenuEvent
      extends InputEvent

  When the user requests a context menu, this event occurs. Context menus can be triggered by the mouse or the keyboard. The exact sequence of mouse or keyboard events that is used to request a menu is platform specific. For example, on Windows, Shift+F10 requests a context menu.

  The event coordinates contain default position for the context menu. For mouse-triggered events it is the position of the mouse cursor, for keyboard-triggered events it is a point inside of bounds of current focus owner (which is the event's target).

  Since:
    JavaFX 2.1
  See Also:
    Serialized Form

- - ### Field Summary

    Fields
    Modifier and Type | Field | Description
    --- | --- | ---
    `static EventType<ContextMenuEvent>` | `ANY` | Common supertype for all context menu event types.
    `static EventType<ContextMenuEvent>` | `CONTEXT_MENU_REQUESTED` | This event occurs when a context menu is requested.

    - ### Fields declared in class javafx.event.Event

      `consumed, eventType, NULL_SOURCE_TARGET, target`

    - ### Fields declared in class java.util.EventObject

      `source`

  - ### Constructor Summary

    Constructors
    Constructor | Description
    --- | ---
    `ContextMenuEvent​(Object source, EventTarget target, EventType<ContextMenuEvent> eventType, double x, double y, double screenX, double screenY, boolean keyboardTrigger, PickResult pickResult)` | Constructs new ContextMenu event.
    `ContextMenuEvent​(EventType<ContextMenuEvent> eventType, double x, double y, double screenX, double screenY, boolean keyboardTrigger, PickResult pickResult)` | Constructs new ContextMenu event with empty source and target.

  - ### Method Summary

    All Methods Instance Methods Concrete Methods
    Modifier and Type | Method | Description
    --- | --- | ---
    `PickResult` | `getPickResult()` | Returns information about the pick.
    `double` | `getSceneX()` | Returns horizontal position of the event relative to the origin of the `Scene` that contains the ContextMenuEvent's source.
    `double` | `getSceneY()` | Returns vertical position of the event relative to the origin of the `Scene` that contains the ContextMenuEvent's source.
    `double` | `getScreenX()` | Returns absolute horizontal position of the event.
    `double` | `getScreenY()` | Returns absolute vertical position of the event.
    `double` | `getX()` | Horizontal position of the event relative to the origin of the ContextMenuEvent's source.
    `double` | `getY()` | Vertical position of the event relative to the origin of the ContextMenuEvent's source.
    `double` | `getZ()` | Depth position of the event relative to the origin of the MouseEvent's source.
    `boolean` | `isKeyboardTrigger()` | Determines whether this event originated from the keyboard.
    `String` | `toString()` | Returns a string representation of this `ContextMenuEvent` object.

    - ### Methods declared in class javafx.event.Event

      `clone, consume, copyFor, fireEvent, getEventType, getTarget, isConsumed`

    - ### Methods declared in class java.util.EventObject

      `getSource`

    - ### Methods declared in class java.lang.Object

      `equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait`

- - ### Field Detail

    - #### CONTEXT_MENU_REQUESTED

          public static final EventType<ContextMenuEvent> CONTEXT_MENU_REQUESTED

      This event occurs when a context menu is requested.

    - #### ANY

          public static final EventType<ContextMenuEvent> ANY

      Common supertype for all context menu event types.
      Since:
        JavaFX 8.0

  - ### Constructor Detail

    - #### ContextMenuEvent

          public ContextMenuEvent​(Object source,
                                  EventTarget target,
                                  EventType<ContextMenuEvent> eventType,
                                  double x,
                                  double y,
                                  double screenX,
                                  double screenY,
                                  boolean keyboardTrigger,
                                  PickResult pickResult)

      Constructs new ContextMenu event.
      Parameters:
        `source` - the source of the event. Can be null.
        `target` - the target of the event. Can be null.
        `eventType` - The type of the event.
        `x` - The x with respect to the scene
        `y` - The y with respect to the scene
        `screenX` - The x coordinate relative to screen.
        `screenY` - The y coordinate relative to screen.
        `keyboardTrigger` - true if this event was triggered by keyboard.
        `pickResult` - pick result. Can be null, in this case a 2D pick result without any further values is constructed based on the scene coordinates and the target
      Since:
        JavaFX 8.0

    - #### ContextMenuEvent

          public ContextMenuEvent​(EventType<ContextMenuEvent> eventType,
                                  double x,
                                  double y,
                                  double screenX,
                                  double screenY,
                                  boolean keyboardTrigger,
                                  PickResult pickResult)

      Constructs new ContextMenu event with empty source and target.
      Parameters:
        `eventType` - The type of the event.
        `x` - The x with respect to the scene.
        `y` - The y with respect to the scene.
        `screenX` - The x coordinate relative to screen.
        `screenY` - The y coordinate relative to screen.
        `keyboardTrigger` - true if this event was triggered by keyboard.
        `pickResult` - pick result. Can be null, in this case a 2D pick result without any further values is constructed based on the scene coordinates
      Since:
        JavaFX 8.0

  - ### Method Detail

    - #### isKeyboardTrigger

          public boolean isKeyboardTrigger()

      Determines whether this event originated from the keyboard.
      Returns:
        true if the event was caused by the keyboard

    - #### getX

          public final double getX()

      Horizontal position of the event relative to the origin of the ContextMenuEvent's source. For more information about this event's coordinate semantics please see the general description of `ContextMenuEvent`.
      Returns:
        horizontal position of the event relative to the origin of the ContextMenuEvent's source.

    - #### getY

          public final double getY()

      Vertical position of the event relative to the origin of the ContextMenuEvent's source. For more information about this event's coordinate semantics please see the general description of `ContextMenuEvent`.
      Returns:
        vertical position of the event relative to the origin of the ContextMenuEvent's source.

    - #### getZ

          public final double getZ()

      Depth position of the event relative to the origin of the MouseEvent's source.
      Returns:
        depth position of the event relative to the origin of the MouseEvent's source.
      Since:
        JavaFX 8.0

    - #### getScreenX

          public final double getScreenX()

      Returns absolute horizontal position of the event. For more information about this event's coordinate semantics please see the general description of `ContextMenuEvent`.
      Returns:
        absolute horizontal position of the event

    - #### getScreenY

          public final double getScreenY()

      Returns absolute vertical position of the event. For more information about this event's coordinate semantics please see the general description of `ContextMenuEvent`.
      Returns:
        absolute vertical position of the event

    - #### getSceneX

          public final double getSceneX()

      Returns horizontal position of the event relative to the origin of the `Scene` that contains the ContextMenuEvent's source. If the node is not in a `Scene`, then the value is relative to the boundsInParent of the root-most parent of the ContextMenuEvent's node. For more information about this event's coordinate semantics please see the general description of `ContextMenuEvent`. Note that in 3D scene, this represents the flat coordinates after applying the projection transformations.
      Returns:
        horizontal position of the event relative to the origin of the `Scene` that contains the ContextMenuEvent's source

    - #### getSceneY

          public final double getSceneY()

      Returns vertical position of the event relative to the origin of the `Scene` that contains the ContextMenuEvent's source. If the node is not in a `Scene`, then the value is relative to the boundsInParent of the root-most parent of the ContextMenuEvent's node. For more information about this event's coordinate semantics please see the general description of `ContextMenuEvent`. Note that in 3D scene, this represents the flat coordinates after applying the projection transformations.
      Returns:
        vertical position of the event relative to the origin of the `Scene` that contains the ContextMenuEvent's source

    - #### getPickResult

          public final PickResult getPickResult()

      Returns information about the pick.
      Returns:
        new PickResult object that contains information about the pick
      Since:
        JavaFX 8.0

    - #### toString

          public String toString()

      Returns a string representation of this `ContextMenuEvent` object.
      Overrides:
        `toString` in class `EventObject`
      Returns:
        a string representation of this `ContextMenuEvent` object.