freddiefujiwara
freddiefujiwara

Reputation: 59029

Can I get file path from Swing to explorer

I read FileTreeDragSource

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

Swing -> explorer I wanna get path with explorer

Upvotes: 0

Views: 824

Answers (2)

Charlie
Charlie

Reputation: 9108

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

Upvotes: 0

ninesided
ninesided

Reputation: 23263

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.

Upvotes: 1

Related Questions