问题
Is there any way to Drag and drop from javaFX scene to windows explorer?
回答1:
Yes there is You should use the onDragDetected function to start your dragEvent and the onDragDone function for doing whatever you want after finishing the drag & drop.
Here an example:
final Text source = new Text(50, 100, "DRAG ME");
source.setOnDragDetected(new EventHandler <MouseEvent>() {
public void handle(MouseEvent event) {
/* drag was detected, start drag-and-drop gesture*/
System.out.println("onDragDetected");
/* allow any transfer mode */
Dragboard db = source.startDragAndDrop(TransferMode.ANY);
/* put a string on dragboard */
ClipboardContent content = new ClipboardContent();
content.putString(source.getText());
db.setContent(content);
event.consume();
}
source.setOnDragDone(new EventHandler <DragEvent>() {
public void handle(DragEvent event) {
/* the drag-and-drop gesture ended */
System.out.println("onDragDone");
/* if the data was successfully moved, clear it */
if (event.getTransferMode() == TransferMode.MOVE) {
source.setText("");
}
event.consume();
}
});
来源:https://stackoverflow.com/questions/23773431/drag-and-drop-from-javafx-scene-to-windows-explorer