Org.eclipse.swt.dnd.DropTarget
lastmod 2026-11-10created 2014-07-243 edits
org.eclipse.swt.dnd.DropTarget is an SWT class that registers a particular control as a drag-and-drop target. You pass the target control and the allowed DND operation types to the constructor, specify the data formats to accept (files, text, etc.) with setTransfer, and then handle the drop event with a DropTargetListener. It is used together with FileTransfer to implement dragging and dropping files from the operating system's file explorer.
Simple SWT File Drag'n'Drop example
DropTarget dt = new DropTarget(tableUpload, DND.DROP_DEFAULT | DND.DROP_MOVE);
dt.setTransfer(new Transfer[] { FileTransfer.getInstance() });
dt.addDropListener(new DropTargetAdapter() {
public void drop(DropTargetEvent event) {
String fileList[] = null;
FileTransfer ft = FileTransfer.getInstance();
if (ft.isSupportedType(event.currentDataType)) {
fileList = (String[]) event.data;
}
}
});