Handling a Drop Event - Java Swing

Java examples for Swing:Drag and Drop

Description

Handling a Drop Event

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 Tutorials