Question on Java Oracle Community (https://community.oracle.com/thread/3934986)
The Problem:
I have set the code below for a Button
which it's full name represents a file path.So when the Button
is dragged to a folder or desktop(let's say in Windows
😛) it is copied by user's Operating System.
I want to get the target folder on which the drop has been done.
Code:
button.setOnDragDetected(event -> {
/* allow copy transfer mode */
Dragboard db = startDragAndDrop(TransferMode.COPY,TransferMode.LINK);
/* put a string on dragboard */
ClipboardContent content = new ClipboardContent();
/*Adding a file into the ClipboardContent*/
content.putFiles(Arrays.asList(new File(getSongPath())));
........//not showing this code....
db.setContent(content);
event.consume();
}
Edit:(29/09/2016)
When the drop is done:
setOnDragDone(d -> {
System.out.println(
"Drag Done,is drop completed?" + d.isDropCompleted() + " , is accepted?" + d.isAccepted());
System.out.println("Accepted Mode:" + d.getAcceptedTransferMode());
System.out.println(" Target:" + d.getTarget() + " Gestoure Target:" + d.getGestureTarget());
});
I get this output where you can see that the Gesture Target == null
Drag Done:true , s drop completed?false , is accepted?true
Accepted Mode:COPY
Target:SmartController$TableViewer@112437[styleClass=table-view] Gesture Target:null
Moreover, drag-and-drop can be implemented between a JavaFX application and a third-party (native) application such as Windows Explorer or a desktop. A drag-and-drop gesture happens as follows: The user click a mouse button on a gesture source, drags the mouse, and releases the mouse button on a gesture target.
A drag-and-drop operation is a data transfer between two objects: a gesture source and a gesture target. The gesture source and gesture target can be the following objects: Nodes. Scenes.
I did some research and it is probably not possible. For example this thread: Get file path for drag-n-drop file on Windows Explorer
You may try this workaround:
This is just an idea for workaround (I didn't fully test it but worth checking)
EDIT 1: Worth reading. How folder detection can be done on Windows:
http://www.codeproject.com/Articles/23207/Drag-and-Drop-to-Windows-Folder-C
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With