import java.io.File; import javafx.application.Application; import javafx.event.EventHandler; import javafx.scene.Group; import javafx.scene.Scene; import javafx.scene.input.DragEvent; import javafx.scene.input.Dragboard; import javafx.scene.input.TransferMode; import javafx.scene.paint.Color; import javafx.stage.Stage; /** * @author cdea */ public class DnDTest extends Application { /** * @param args the command line arguments */ public static void main(String[] args) { Application.launch(args); } @Override public void start(Stage primaryStage) { Group root = new Group(); Scene scene = new Scene(root, 551, 400, Color.BLACK); // Dragging over surface scene.setOnDragOver(new EventHandler() { @Override public void handle(DragEvent event) { Dragboard db = event.getDragboard(); if (db.hasFiles()) { event.acceptTransferModes(TransferMode.COPY); } else { event.consume(); } } }); // Dropping over surface scene.setOnDragDropped(new EventHandler() { @Override public void handle(DragEvent event) { Dragboard db = event.getDragboard(); boolean success = false; if (db.hasFiles()) { success = true; for (File file:db.getFiles()) { System.out.println("file: " + file); } } event.setDropCompleted(success); event.consume(); } }); primaryStage.setScene(scene); primaryStage.show(); } }