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

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2021-04-12
  • 2022-12-23
  • 2022-02-08
  • 2022-12-23
  • 2021-11-28
猜你喜欢
  • 2021-06-26
  • 2021-09-20
  • 2021-11-11
  • 2022-01-12
  • 2022-12-23
  • 2021-09-26
  • 2021-12-22
相关资源
相似解决方案