tags:

views:

232

answers:

2

I read FileTreeDragSource

Can I get file path from Swing to explorer. Not explorer -> Swing!!

Swing -> explorer I wanna get path with explorer

+1  A: 

Java's DnD support does allow you to drag things out of a Java application into a native one, but I think that it's limited to text and only alows target components which will accept text, like the address bar in a browser.

If the explorer address bar does not accept text from a drag and drop, you could always add a menu option to your application to "Open in Explorer" which just launches a new Explorer process with the file path as a parameter.

ninesided
Thank you. I can grasp the file of the origin of copy, but will it be impossible to grasp the file of the copy ?
ffffff
I think perhaps I am misunderstanding your question. Are you trying to drag and drop a File object from a Java application, to an Explorer window and have it copied to that location? Or are you trying to copy the *path* of a file from Java to the Explorer window? If the former, this is not possible.
ninesided
Yes Java to the Explorer window.Why not?
ffffff
A: 

Use this as your Transferable and you should be golden!

public class FileList extends Vector<File> implements Transferable {
     final static int FILE = 0;
     DataFlavor flavors[] = {DataFlavor.javaFileListFlavor};
     public FileList(File file) {addElement(file);}
     public synchronized DataFlavor[] getTransferDataFlavors() {return flavors;}
     public boolean isDataFlavorSupported(DataFlavor flavor) {
      return flavor.equals(flavors[FILE]);
     }
     public synchronized Object getTransferData(DataFlavor flavor) throws UnsupportedFlavorException, IOException {
      if (flavor.equals(flavors[FILE])) return this;
      else throw new UnsupportedFlavorException(flavor);
     }
    }
Charlie