Java Reference
In-Depth Information
Once the drag-over event handler attribute is set, you create a drag-dropped event
handler attribute so it can finalize the operation. Listening to a drag-dropped event is
similar to listening to a drag-over event in which the handle() method will be im-
plemented via a lambda expression. Once again, you obtain the Dragboard object
from the event to determine whether the clipboard contains any files. If it does, the list
of files is iterated and the file names are added to the imageFiles list. This code
demonstrates setting up a scene's OnDragDropped attribute:
// Dropping over surface
scene.setOnDragDropped((DragEvent event) -> {
Dragboard db = event.getDragboard();
boolean success = false;
if (db.hasFiles()) {
success = true;
String filePath = null;
for (File file : db.getFiles()) {
filePath = file.getAbsolutePath();
System.out.println(filePath);
currentIndex += 1;
imageFiles.add(currentIndex, filePath);
}
filePath = filePrefix + filePath;
// set new image as the image to show.
Image imageimage = new Image(filePath);
currentImageView.setImage(imageimage);
}
event.setDropCompleted(success);
event.consume();
});
As the last file is determined, the current image is displayed. The following code
demonstrates loading an image to be displayed:
// set new image as the image to show.
Image imageimage = new Image(filePath);
currentImageView.setImage(imageimage);
Search WWH ::




Custom Search