- java.lang.Object
-
- javax.swing.TransferHandler.TransferSupport
-
- Enclosing class:
- TransferHandler
public static final class TransferHandler.TransferSupport extends Object
This class encapsulates all relevant details of a clipboard or drag and drop transfer, and also allows for customizing aspects of the drag and drop experience.The main purpose of this class is to provide the information needed by a developer to determine the suitability of a transfer or to import the data contained within. But it also doubles as a controller for customizing properties during drag and drop, such as whether or not to show the drop location, and which drop action to use.
Developers typically need not create instances of this class. Instead, they are something provided by the DnD implementation to certain methods in
TransferHandler.
-
-
Constructor Summary
Constructors Constructor and Description TransferHandler.TransferSupport(Component component, Transferable transferable)Create aTransferSupportwithisDrop()falsefor the given component andTransferable.
-
Method Summary
Methods Modifier and Type Method and Description ComponentgetComponent()Returns the target component of this transfer.DataFlavor[]getDataFlavors()Returns the data flavors for this transfer.intgetDropAction()Returns the action chosen for the drop, when thisTransferSupportrepresents a drop.TransferHandler.DropLocationgetDropLocation()Returns the current (non-null) drop location for the component, when thisTransferSupportrepresents a drop.intgetSourceDropActions()Returns the drag source's supported drop actions, when thisTransferSupportrepresents a drop.TransferablegetTransferable()Returns theTransferableassociated with this transfer.intgetUserDropAction()Returns the user drop action for the drop, when thisTransferSupportrepresents a drop.booleanisDataFlavorSupported(DataFlavor df)Returns whether or not the given data flavor is supported.booleanisDrop()Returns whether or not thisTransferSupportrepresents a drop operation.voidsetDropAction(int dropAction)Sets the drop action for the transfer - which must represent a drop - to the given action, instead of the default user drop action.voidsetShowDropLocation(boolean showDropLocation)Sets whether or not the drop location should be visually indicated for the transfer - which must represent a drop.
-
-
-
Constructor Detail
-
TransferHandler.TransferSupport
public TransferHandler.TransferSupport(Component component, Transferable transferable)
Create aTransferSupportwithisDrop()falsefor the given component andTransferable.- Parameters:
component- the target componenttransferable- the transferable- Throws:
NullPointerException- if either parameter isnull
-
-
Method Detail
-
isDrop
public boolean isDrop()
Returns whether or not thisTransferSupportrepresents a drop operation.- Returns:
trueif this is a drop operation,falseotherwise.
-
getComponent
public Component getComponent()
Returns the target component of this transfer.- Returns:
- the target component
-
getDropLocation
public TransferHandler.DropLocation getDropLocation()
Returns the current (non-null) drop location for the component, when thisTransferSupportrepresents a drop.Note: For components with built-in drop support, this location will be a subclass of
DropLocationof the same type returned by that component'sgetDropLocationmethod.This method is only for use with drag and drop transfers. Calling it when
isDrop()isfalseresults in anIllegalStateException.- Returns:
- the drop location
- Throws:
IllegalStateException- if this is not a drop- See Also:
isDrop()
-
setShowDropLocation
public void setShowDropLocation(boolean showDropLocation)
Sets whether or not the drop location should be visually indicated for the transfer - which must represent a drop. This is applicable to those components that automatically show the drop location when appropriate during a drag and drop operation). By default, the drop location is shown only when theTransferHandlerhas said it can accept the import represented by thisTransferSupport. With this method you can force the drop location to always be shown, or always not be shown.This method is only for use with drag and drop transfers. Calling it when
isDrop()isfalseresults in anIllegalStateException.- Parameters:
showDropLocation- whether or not to indicate the drop location- Throws:
IllegalStateException- if this is not a drop- See Also:
isDrop()
-
setDropAction
public void setDropAction(int dropAction)
Sets the drop action for the transfer - which must represent a drop - to the given action, instead of the default user drop action. The action must be supported by the source's drop actions, and must be one ofCOPY,MOVEorLINK.This method is only for use with drag and drop transfers. Calling it when
isDrop()isfalseresults in anIllegalStateException.- Parameters:
dropAction- the drop action- Throws:
IllegalStateException- if this is not a dropIllegalArgumentException- if an invalid action is specified- See Also:
getDropAction(),getUserDropAction(),getSourceDropActions(),isDrop()
-
getDropAction
public int getDropAction()
Returns the action chosen for the drop, when thisTransferSupportrepresents a drop.Unless explicitly chosen by way of
setDropAction, this returns the user drop action provided bygetUserDropAction.You may wish to query this in
TransferHandler'simportDatamethod to customize processing based on the action.This method is only for use with drag and drop transfers. Calling it when
isDrop()isfalseresults in anIllegalStateException.- Returns:
- the action chosen for the drop
- Throws:
IllegalStateException- if this is not a drop- See Also:
setDropAction(int),getUserDropAction(),isDrop()
-
getUserDropAction
public int getUserDropAction()
Returns the user drop action for the drop, when thisTransferSupportrepresents a drop.The user drop action is chosen for a drop as described in the documentation for
DropTargetDragEventandDropTargetDropEvent. A different action may be chosen as the drop action by way of thesetDropActionmethod.You may wish to query this in
TransferHandler'scanImportmethod when determining the suitability of a drop or when deciding on a drop action to explicitly choose.This method is only for use with drag and drop transfers. Calling it when
isDrop()isfalseresults in anIllegalStateException.- Returns:
- the user drop action
- Throws:
IllegalStateException- if this is not a drop- See Also:
setDropAction(int),getDropAction(),isDrop()
-
getSourceDropActions
public int getSourceDropActions()
Returns the drag source's supported drop actions, when thisTransferSupportrepresents a drop.The source actions represent the set of actions supported by the source of this transfer, and are represented as some bitwise-OR combination of
COPY,MOVEandLINK. You may wish to query this inTransferHandler'scanImportmethod when determining the suitability of a drop or when deciding on a drop action to explicitly choose. To determine if a particular action is supported by the source, bitwise-AND the action with the source drop actions, and then compare the result against the original action. For example:boolean copySupported = (COPY & getSourceDropActions()) == COPY;
This method is only for use with drag and drop transfers. Calling it when
isDrop()isfalseresults in anIllegalStateException.- Returns:
- the drag source's supported drop actions
- Throws:
IllegalStateException- if this is not a drop- See Also:
isDrop()
-
getDataFlavors
public DataFlavor[] getDataFlavors()
Returns the data flavors for this transfer.- Returns:
- the data flavors for this transfer
-
isDataFlavorSupported
public boolean isDataFlavorSupported(DataFlavor df)
Returns whether or not the given data flavor is supported.- Parameters:
df- theDataFlavorto test- Returns:
- whether or not the given flavor is supported.
-
getTransferable
public Transferable getTransferable()
Returns theTransferableassociated with this transfer.Note: Unless it is necessary to fetch the
Transferabledirectly, use one of the other methods on this class to inquire about the transfer. This may perform better than fetching theTransferableand asking it directly.- Returns:
- the
Transferableassociated with this transfer
-
-
Traduction non disponible
Les API Java ne sont pas encore traduites en français sur l'infobrol. Seule la version anglaise est disponible pour l'instant.
Version en cache
24/10/2025 05:35:04 Cette version de la page est en cache (à la date du 24/10/2025 05:35:04) afin d'accélérer le traitement.Vous pouvez activer le mode utilisateur dans le menu en haut pour afficher la version plus récente de la page.
Document créé le 11/06/2005, dernière modification le 04/03/2020
Source du document imprimé : https://www.gaudry.be/java-api-rf-javax/swing/TransferHandler.TransferSupport.html
L'infobrol est un site personnel dont le contenu n'engage que moi. Le texte est mis à disposition sous licence CreativeCommons(BY-NC-SA). Plus d'info sur les conditions d'utilisation et sur l'auteur.
Références
Ces références et liens indiquent des documents consultés lors de la rédaction de cette page, ou qui peuvent apporter un complément d'information, mais les auteurs de ces sources ne peuvent être tenus responsables du contenu de cette page.
L'auteur de ce site est seul responsable de la manière dont sont présentés ici les différents concepts, et des libertés qui sont prises avec les ouvrages de référence. N'oubliez pas que vous devez croiser les informations de sources multiples afin de diminuer les risques d'erreurs.