Class NativeDropEvent
One step of a native operating system drag passing over, or landing on, a component that was
marked as a native drop target with Component#setNativeDropTarget(boolean).
The payload is a ClipboardContent -- the same shape a paste produces -- so a component that
already knows how to paste knows how to accept a drop. Inspect
ClipboardContent#getMimeTypes() and take the richest representation you understand, exactly
as you would for a paste.
The x and y inherited from ActionEvent are absolute screen coordinates within the surface
the drag is over, so Component#getAbsoluteX() and Component#getAbsoluteY() convert them
to component coordinates.
Accepting
A drag event tells the operating system whether the drop would be allowed and what would
happen. Call #accept(int) with one of the actions in #getAllowedActions() to show the
user the corresponding cursor, or #reject() to refuse. A target that never calls either
accepts NativeDragOperation#ACTION_COPY when the source allows it, which is what most
targets want.
-
Nested Class Summary
Nested classes/interfaces inherited from class ActionEvent
ActionEvent.Type -
Method Summary
Modifier and TypeMethodDescriptionvoidaccept(int action) Accepts the drag, telling the operating system what dropping here would do.intReturns the action this target has accepted, orNativeDragOperation#ACTION_NONEwhen it has refused the drop.intReturns the bit set of actions the drag source permits.Returns the dragged payload.String[]getFiles()Returns the file paths carried by the drag, or null when it carries none.Returns the component the drag is over.getText()Returns the plain text carried by the drag, or null when it carries none.booleanisLocal()Returns true when the drag started inside this application rather than in another application or on the desktop.voidreject()Refuses the drag, so the user sees a "no drop" cursor over this component and no drop event is delivered.Methods inherited from class ActionEvent
consume, getActualComponent, getCommand, getComponent, getDraggedComponent, getDropTarget, getEventType, getKeyEvent, getPointerEvent, getProgress, getSource, getX, getY, isConsumed, isLongEvent, isPointerPressedDuringDrag, setPointerEvent, setPointerPressedDuringDrag
-
Method Details
-
getContent
Returns the dragged payload. -
getTarget
Returns the component the drag is over. -
getAllowedActions
public int getAllowedActions()Returns the bit set of actions the drag source permits. -
isLocal
public boolean isLocal()Returns true when the drag started inside this application rather than in another application or on the desktop. A target that reorders its own items usually only wants to handle local drags, and a target that imports foreign data usually only wants the rest. -
getFiles
Returns the file paths carried by the drag, or null when it carries none. This is the representation a drag out of a file manager or off the desktop arrives with. -
getText
Returns the plain text carried by the drag, or null when it carries none. -
getAcceptedAction
public int getAcceptedAction()Returns the action this target has accepted, orNativeDragOperation#ACTION_NONEwhen it has refused the drop. -
accept
public void accept(int action) Accepts the drag, telling the operating system what dropping here would do. An action the source does not allow is refused rather than silently substituted, because showing the user a move cursor for a drag that can only copy is worse than showing no cursor.
Parameters
action: one ofNativeDragOperation#ACTION_COPY,NativeDragOperation#ACTION_MOVEorNativeDragOperation#ACTION_LINK
-
reject
public void reject()Refuses the drag, so the user sees a "no drop" cursor over this component and no drop event is delivered.
-