3

I need to get the dropped files' paths. I have implemented the drop(DropTargetDropEvent e) method in my JFrame which implements DropTargetListener which has the following code:

public void drop(DropTargetDropEvent e) {
    Transferable tr = e.getTransferable();
    e.acceptDrop (DnDConstants.ACTION_REFERENCE);

    try {
          System.out.println(tr.getTransferData(DataFlavor.getTextPlainUnicodeFlavor()));
    } catch (UnsupportedFlavorException e1) {
        e1.printStackTrace();
    } catch (IOException e1) {
        e1.printStackTrace();
    }

     e.getDropTargetContext().dropComplete(true);
}
Kara
  • 6,115
  • 16
  • 50
  • 57
john bess
  • 31
  • 3

1 Answers1

1

The section from the Swing tutorial on Top Level Drop has a working example. It looks like it uses DataFlavor.javaFileListFlavor.

camickr
  • 321,443
  • 19
  • 166
  • 288