This method is called repeatedly during a drag and drop operation to allow the developer to configure properties of, and to return the acceptability of transfers; with a return value of
true
indicating that the transfer represented by the given
TransferSupport
(which contains all of the details of the transfer) is acceptable at the current time, and a value of
false
rejecting the transfer.
For those components that automatically display a drop location during drag and drop, accepting the transfer, by default, tells them to show the drop location. This can be changed by calling setShowDropLocation
on the TransferSupport
.
By default, when the transfer is accepted, the chosen drop action is that picked by the user via their drag gesture. The developer can override this and choose a different action, from the supported source actions, by calling setDropAction
on the TransferSupport
.
On every call to canImport
, the TransferSupport
contains fresh state. As such, any properties set on it must be set on every call. Upon a drop, canImport
is called one final time before calling into importData
. Any state set on the TransferSupport
during that last call will be available in importData
.
This method is not called internally in response to paste operations. As such, it is recommended that implementations of importData
explicitly call this method for such cases and that this method be prepared to return the suitability of paste operations as well.
Note: The TransferSupport
object passed to this method is only valid for the duration of the method call. It is undefined what values it may contain after this method returns.