The drop target in this example only accepts dropped String
objects. A drop target must implement DropTargetListener
and supply an implementation for drop()
.
public void drop(DropTargetDropEvent evt) {
try {
Transferable t = evt.getTransferable();
if (t.isDataFlavorSupported(DataFlavor.stringFlavor)) {
evt.acceptDrop(DnDConstants.ACTION_COPY_OR_MOVE);
String s = (String)t.getTransferData(DataFlavor.stringFlavor);
evt.getDropTargetContext().dropComplete(true);
process(s);
} else {
evt.rejectDrop();
}
} catch (IOException e) {
evt.rejectDrop();
} catch (UnsupportedFlavorException e) {
evt.rejectDrop();
}
}
Related Examples |