You can clearly accept multiple files in a DragEvent
.
The following example displays the file names dropped to the scene:
@Override
public void start(Stage primaryStage) {
Text text = new Text();
StackPane root = new StackPane(text);
root.setOnDragOver(evt -> {
if (evt.getDragboard().hasFiles()) {
evt.acceptTransferModes(TransferMode.LINK);
}
});
root.setOnDragDropped(evt -> {
text.setText(evt.getDragboard().getFiles().stream().map(File::getAbsolutePath).collect(Collectors.joining("
")));
evt.setDropCompleted(true);
});
Scene scene = new Scene(root, 400, 400);
primaryStage.setScene(scene);
primaryStage.show();
}
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…