MouseDragEvent (JavaFX 27)
Description: declaration: module: javafx.graphics, package: javafx.scene.input, class: MouseDragEvent

# Class MouseDragEvent

java.lang.Object
java.util.EventObject
javafx.event.Event
javafx.scene.input.InputEvent
javafx.scene.input.MouseEvent
javafx.scene.input.MouseDragEvent

All Implemented Interfaces:
  `Serializable, Cloneable`

public final class MouseDragEvent extends MouseEvent
Mouse drag events are delivered to potential gesture targets during full press-drag-release gestures. The difference among different gesture types is described at `MouseEvent`.

Full press-drag-release gesture can be started by calling `startFullDrag()` (on a node or scene) inside of a DRAG_DETECTED event handler. This call activates delivering of `MouseDragEvent`s to the nodes that are under cursor during the dragging gesture.

When you drag a node, it's still under cursor, so it is considered being a potential gesture target during the whole gesture. If you need to drag a node to a different node and let the other node know about it, you need to ensure that the nodes under the dragged node are picked as the potential gesture targets. You can achieve this by calling `setMouseTransparent(true)` on the dragged node in a `MOUSE_PRESSED` handler and returning it back to false in a `MOUSE_RELEASED` handler. This way the nodes under the dragged node will receive the `MouseDragEvent`s, while all the `MouseEvent`s will still be delivered to the (currently mouse transparent) gesture source.

The entered/exited events behave similarly to mouse entered/exited events, please see `MouseEvent` overview.

Since:
  JavaFX 2.1
See Also:
  - Serialized Form

- ## Field Summary

  Fields
  Modifier and Type
  Field
  Description
  `static final EventType<MouseDragEvent>`
  `ANY`
  Common supertype for all mouse event types.
  `static final EventType<MouseDragEvent>`
  `MOUSE_DRAG_DONE`
  This event occurs when the gesture ends.
  `static final EventType<MouseDragEvent>`
  `MOUSE_DRAG_ENTERED`
  This event occurs when the gesture enters a node.
  `static final EventType<MouseDragEvent>`
  `MOUSE_DRAG_ENTERED_TARGET`
  This event occurs when the gesture enters a node.
  `static final EventType<MouseDragEvent>`
  `MOUSE_DRAG_EXITED`
  This event occurs when the gesture exits a node.
  `static final EventType<MouseDragEvent>`
  `MOUSE_DRAG_EXITED_TARGET`
  This event occurs when the gesture exits a node.
  `static final EventType<MouseDragEvent>`
  `MOUSE_DRAG_OVER`
  This event occurs when the gesture progresses within a node.
  `static final EventType<MouseDragEvent>`
  `MOUSE_DRAG_RELEASED`
  This event occurs when the gesture is released over a node (by releasing the mouse button).

  ### Fields declared in class MouseEvent

  `DRAG_DETECTED, MOUSE_CLICKED, MOUSE_DRAGGED, MOUSE_ENTERED, MOUSE_ENTERED_TARGET, MOUSE_EXITED, MOUSE_EXITED_TARGET, MOUSE_MOVED, MOUSE_PRESSED, MOUSE_RELEASED`

  ### Fields declared in class Event

  `consumed, eventType, NULL_SOURCE_TARGET, target`

  ### Fields declared in class EventObject

  `source`

- ## Constructor Summary

  Constructors
  Constructor
  Description
  `MouseDragEvent(Object source, EventTarget target, EventType<MouseDragEvent> eventType, double x, double y, double screenX, double screenY, MouseButton button, int clickCount, boolean shiftDown, boolean controlDown, boolean altDown, boolean metaDown, boolean primaryButtonDown, boolean middleButtonDown, boolean secondaryButtonDown, boolean backButtonDown, boolean forwardButtonDown, boolean synthesized, boolean popupTrigger, PickResult pickResult, Object gestureSource)`
  Constructs new MouseDragEvent event.
  `MouseDragEvent(Object source, EventTarget target, EventType<MouseDragEvent> eventType, double x, double y, double screenX, double screenY, MouseButton button, int clickCount, boolean shiftDown, boolean controlDown, boolean altDown, boolean metaDown, boolean primaryButtonDown, boolean middleButtonDown, boolean secondaryButtonDown, boolean synthesized, boolean popupTrigger, PickResult pickResult, Object gestureSource)`
  Constructs new MouseDragEvent event.
  `MouseDragEvent(EventType<MouseDragEvent> eventType, double x, double y, double screenX, double screenY, MouseButton button, int clickCount, boolean shiftDown, boolean controlDown, boolean altDown, boolean metaDown, boolean primaryButtonDown, boolean middleButtonDown, boolean secondaryButtonDown, boolean synthesized, boolean popupTrigger, PickResult pickResult, Object gestureSource)`
  Constructs new MouseDragEvent event with null source and target.

- ## Method Summary

  Modifier and Type
  Method
  Description
  `MouseDragEvent`
  `copyFor(Object newSource, EventTarget newTarget)`
  Copies this event for a different source and target.
  `MouseDragEvent`
  `copyFor(Object newSource, EventTarget newTarget, EventType<? extends MouseEvent> type)`
  Creates a copy of the given event with the given fields substituted.
  `EventType<MouseDragEvent>`
  `getEventType()`
  Gets the event type of this event.
  `Object`
  `getGestureSource()`
  Returns the source object of the ongoing gesture.
  `String`
  `toString()`
  Returns a string representation of this `MouseDragEvent` object.

  ### Methods declared in class MouseEvent

  `copyForMouseDragEvent, getButton, getClickCount, getPickResult, getSceneX, getSceneY, getScreenX, getScreenY, getX, getY, getZ, isAltDown, isBackButtonDown, isControlDown, isDragDetect, isForwardButtonDown, isMetaDown, isMiddleButtonDown, isPopupTrigger, isPrimaryButtonDown, isSecondaryButtonDown, isShiftDown, isShortcutDown, isStillSincePress, isSynthesized, setDragDetect`

  ### Methods declared in class Event

  `clone, consume, fireEvent, getTarget, isConsumed`

  ### Methods declared in class EventObject

  `getSource`

  ### Methods declared in class Object

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

- ## Field Details

  - ### ANY

    public static final EventType<MouseDragEvent> ANY
    Common supertype for all mouse event types.

  - ### MOUSE_DRAG_OVER

    public static final EventType<MouseDragEvent> MOUSE_DRAG_OVER
    This event occurs when the gesture progresses within a node.

  - ### MOUSE_DRAG_RELEASED

    public static final EventType<MouseDragEvent> MOUSE_DRAG_RELEASED
    This event occurs when the gesture is released over a node (by releasing the mouse button).

  - ### MOUSE_DRAG_ENTERED_TARGET

    public static final EventType<MouseDragEvent> MOUSE_DRAG_ENTERED_TARGET
    This event occurs when the gesture enters a node. It's the bubbling variant, which is delivered also to all parents of the entered node (unless it was consumed). When notifications about mouse entering some of node's children are not desired, `MOUSE_DRAG_ENTERED` event handler should be used.
    See Also:
      - MouseEvent for more information about mouse entered/exited handling which is similar

  - ### MOUSE_DRAG_ENTERED

    public static final EventType<MouseDragEvent> MOUSE_DRAG_ENTERED
    This event occurs when the gesture enters a node. This event type is delivered only to the entered node, if parents want to filter it or get the bubbling event, they need to use `MOUSE_DRAG_ENTERED_TARGET`.
    See Also:
      - MouseEvent for more information about mouse entered/exited handling which is similar

  - ### MOUSE_DRAG_EXITED_TARGET

    public static final EventType<MouseDragEvent> MOUSE_DRAG_EXITED_TARGET
    This event occurs when the gesture exits a node. It's the bubbling variant, which is delivered also to all parents of the exited node (unless it was consumed). When notifications about mouse exiting some of node's children are not desired, `MOUSE_DRAG_EXITED` event handler should be used.
    See Also:
      - MouseEvent for more information about mouse entered/exited handling which is similar

  - ### MOUSE_DRAG_EXITED

    public static final EventType<MouseDragEvent> MOUSE_DRAG_EXITED
    This event occurs when the gesture exits a node. This event type is delivered only to the exited node, if parents want to filter it or get the bubbling event, they need to use `MOUSE_DRAG_EXITED_TARGET`.
    See Also:
      - MouseEvent for more information about mouse entered/exited handling which is similar

  - ### MOUSE_DRAG_DONE

    public static final EventType<MouseDragEvent> MOUSE_DRAG_DONE
    This event occurs when the gesture ends. It is delivered exactly once to the gesture source, and is always the last event in the full press-drag-release process. It is delivered even when the mouse is outside the window.
    Since:
      26

- ## Constructor Details

  - ### MouseDragEvent

    public MouseDragEvent(Object source, EventTarget target, EventType<MouseDragEvent> eventType, double x, double y, double screenX, double screenY, MouseButton button, int clickCount, boolean shiftDown, boolean controlDown, boolean altDown, boolean metaDown, boolean primaryButtonDown, boolean middleButtonDown, boolean secondaryButtonDown, boolean synthesized, boolean popupTrigger, PickResult pickResult, Object gestureSource)
    Constructs new MouseDragEvent event. Both `MouseEvent.isBackButtonDown()` and `MouseEvent.isForwardButtonDown()` will return false for this event
    Parameters:
      `source` - the source of the event, which can be `null`
      `target` - the target of the event, which 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
      `button` - the mouse button used
      `clickCount` - number of click counts
      `shiftDown` - true if shift modifier was pressed
      `controlDown` - true if control modifier was pressed
      `altDown` - true if alt modifier was pressed
      `metaDown` - true if meta modifier was pressed
      `primaryButtonDown` - true if primary button was pressed
      `middleButtonDown` - true if middle button was pressed
      `secondaryButtonDown` - true if secondary button was pressed
      `synthesized` - if this event was synthesized
      `popupTrigger` - whether this event denotes a popup trigger for current platform
      `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 target
      `gestureSource` - source object of the ongoing gesture
    Since:
      JavaFX 8.0

  - ### MouseDragEvent

    public MouseDragEvent(Object source, EventTarget target, EventType<MouseDragEvent> eventType, double x, double y, double screenX, double screenY, MouseButton button, int clickCount, boolean shiftDown, boolean controlDown, boolean altDown, boolean metaDown, boolean primaryButtonDown, boolean middleButtonDown, boolean secondaryButtonDown, boolean backButtonDown, boolean forwardButtonDown, boolean synthesized, boolean popupTrigger, PickResult pickResult, Object gestureSource)
    Constructs new MouseDragEvent event.
    Parameters:
      `source` - the source of the event, which can be `null`
      `target` - the target of the event, which 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
      `button` - the mouse button used
      `clickCount` - number of click counts
      `shiftDown` - true if shift modifier was pressed
      `controlDown` - true if control modifier was pressed
      `altDown` - true if alt modifier was pressed
      `metaDown` - true if meta modifier was pressed
      `primaryButtonDown` - true if primary button was pressed
      `middleButtonDown` - true if middle button was pressed
      `secondaryButtonDown` - true if secondary button was pressed
      `backButtonDown` - true if back button was pressed
      `forwardButtonDown` - true if forward button was pressed
      `synthesized` - if this event was synthesized
      `popupTrigger` - whether this event denotes a popup trigger for current platform
      `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 target
      `gestureSource` - source object of the ongoing gesture
    Since:
      12

  - ### MouseDragEvent

    public MouseDragEvent(EventType<MouseDragEvent> eventType, double x, double y, double screenX, double screenY, MouseButton button, int clickCount, boolean shiftDown, boolean controlDown, boolean altDown, boolean metaDown, boolean primaryButtonDown, boolean middleButtonDown, boolean secondaryButtonDown, boolean synthesized, boolean popupTrigger, PickResult pickResult, Object gestureSource)
    Constructs new MouseDragEvent event with null source and target. Both `MouseEvent.isBackButtonDown()` and `MouseEvent.isForwardButtonDown()` will return false for this event.
    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
      `button` - the mouse button used
      `clickCount` - number of click counts
      `shiftDown` - true if shift modifier was pressed
      `controlDown` - true if control modifier was pressed
      `altDown` - true if alt modifier was pressed
      `metaDown` - true if meta modifier was pressed
      `primaryButtonDown` - true if primary button was pressed
      `middleButtonDown` - true if middle button was pressed
      `secondaryButtonDown` - true if secondary button was pressed
      `synthesized` - if this event was synthesized
      `popupTrigger` - whether this event denotes a popup trigger for current platform
      `pickResult` - pick result. Can be null, in this case a 2D pick result without any further values is constructed based on the scene coordinates
      `gestureSource` - source object of the ongoing gesture
    Since:
      JavaFX 8.0

- ## Method Details

  - ### getGestureSource

    public Object getGestureSource()
    Returns the source object of the ongoing gesture. Gesture source is the object that started the full press-drag-release gesture (by `startFullDrag` method being called on it).
    Returns:
      The source object of the gesture.

  - ### toString

    public String toString()
    Returns a string representation of this `MouseDragEvent` object.
    Overrides:
      `toString` in class `MouseEvent`
    Returns:
      a string representation of this `MouseDragEvent` object.

  - ### copyFor

    public MouseDragEvent copyFor(Object newSource, EventTarget newTarget)
    Description copied from class: `MouseEvent`
    Copies this event for a different source and target. In most cases you don't need to use this method, it's called automatically when you fire the event.
    Overrides:
      `copyFor` in class `MouseEvent`
    Parameters:
      `newSource` - New event source
      `newTarget` - New event target
    Returns:
      copy of this event for a different source and target

  - ### copyFor

    public MouseDragEvent copyFor(Object newSource, EventTarget newTarget, EventType<? extends MouseEvent> type)
    Description copied from class: `MouseEvent`
    Creates a copy of the given event with the given fields substituted.
    Overrides:
      `copyFor` in class `MouseEvent`
    Parameters:
      `newSource` - the new source of the copied event
      `newTarget` - the new target of the copied event
      `type` - the new eventType
    Returns:
      the event copy with the fields substituted

  - ### getEventType

    public EventType<MouseDragEvent> getEventType()
    Description copied from class: `Event`
    Gets the event type of this event. Objects of the same `Event` class can have different event types. These event types further specify what kind of event occurred.
    Overrides:
      `getEventType` in class `Event`
    Returns:
      the event type