The
dragEnter
event handler is a special user-defined
Function
that can be added to a component when it is created
and that will be called automatically with a single
DropTargetEvent
or
DragSourceEvent
argument whenever the cursor enters certain components.
The details, which are discussed below, depend on the type assigned
to the
event
argument in the
dragEnter
declaration.
A
dragEnter
event handler can only be added via
addEventHandler
after a component is created,
but an existing
dragEnter
event handler can always be changed or temporarily disabled,
which is what happens when
NULL,
is assigned to
dragEnter.
The type that is assigned to the
event
argument in the declaration of
dragEnter
selects the events that
dragEnter
receives.
If
event
is declared to be a
DropTargetEvent
then
DragSourceEvents
will not arrive, if it is declared to be a
DragSourceEvent
then
DropTargetEvents
will not arrive, but if
event
is an
Object
then
DropTargetEvents
and
DragSourceEvents
can arrive and
dragEnter
should check
event,
usually using
instanceof,
to decide what to do.
In most situations
dragEnter
and
drop
are the only two event handlers a component will implement when it
wants to accept data that is being transferred by a drag and drop
operation.
dragEnter
receives
DropTargetEvents
when its declaration lets them through and the cursor enters the component.
dragEnter
usually examines fields, like
dragowner,
mimetypes,
and
transferable
in its
event
argument and then returns a
Number
that is non-zero if it accepts and zero if it rejects the data that
is being transferred by the drag and drop operation.
A return value that is missing or the wrong type (e.g., a
String)
also means the data is rejected.
A much less important use of
dragEnter
is as an event handler that receives
DragSourceEvents,
which happens when its declaration lets them through and the cursor
enters any component that accepts
the data that this component's
dragGestureRecognized
exported.
dragEnter
may choose to change the
cursor
field in its
event
argument if a visual effect is called for,
but in this case nothing special is required and any return value from
dragEnter
will be ignored.
Some Swing components provide automatic drag and drop handling that
currently must be disabled by storing
NULL
in their
transferhandler
field before your drag and drop event handlers will start working.
In other words, you probably should include a declaration that looks
something like,
Object transferhandler = NULL;
whenever you build a Swing component provides its own drag and drop
event handlers.
| |
| Return: |
Number
or none
| | |
| See Also: |
actionPerformed,
addEventHandler,
adjustmentValueChanged,
caretUpdate,
componentHidden,
componentMoved,
componentResized,
componentShown,
dragDropEnd,
dragExit,
DragGestureEvent,
dragGestureRecognized,
dragMouseMoved,
dragOver,
DragSourceEvent,
drop,
dropActionChanged,
DropTargetEvent,
focusGained,
focusLost,
hyperlinkActivated,
hyperlinkEntered,
hyperlinkExited,
invocationAction,
invocationBrowse,
invocationChange,
invocationEdit,
invocationEditKey,
invocationRun,
invocationSelection,
itemStateChanged,
keyPressed,
keyReleased,
keyTyped,
mouseClicked,
mouseDragged,
mouseEntered,
mouseExited,
mouseMoved,
mousePressed,
mouseReleased,
mouseWheelMoved,
removeEventHandler,
stateChanged,
textValueChanged,
valueChanged,
windowActivated,
windowClosed,
windowClosing,
windowDeactivated,
windowDeiconified,
windowIconified,
windowOpened
|
|