Key concepts
The core class in Java Drag and Drop (DnD) is the TransferHandler. This can be used to transfer data to and from both Java and native applications in the same way.
- All JComponents support DnD automatically. Use the
setDragEnabledto enable the default behaviour for the component. - DnD to and from any JComponent can be customised by calling
setTransferHandlerwith your own TransferHandler. - To provide the effect of being able to drop something anywhere on the application, assign a suitable TransferHandler to all components from the JPanel downwards.
- Assigning a TransferHandler overrides the default behaviour. Careful consideration should be made if there are complex requirements.
TransferHandler Drag Methods
When sub-classing a TransferHandler, the following are the methods to override to control the drag source behaviour.
getSourceActionsControls which drag types are supported from this component.createTransferrableWhen a drag is started, the data to send is bundled up into aTransferablewhich will be delivered to the drop target.exportDoneSignalled when a drag has been completed using this TransferHandler.
TransferHandler Drop Methods
The drop methods below control the behaviour of a component which is to be the drop target for a DnD operation.
canImportCalled repeatedly to determine whether the component to receive the drop is able to.startImportCalled when the drop is initiated.
No comments:
Post a Comment