开发者

how to get file paths from files dragged from windows explorer into JFrame in Java

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);
}


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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜