Drag, Drop and Move Around Images

61 views Asked by At

I'm creating an interface that allows users to drag an image from outside the program and drop it into an imageview within a gridpane.

Currently, the interface is able to handle drag and drop photos, but once its dropping and I cannot move it again.

@FXML
void imageViewDragDropped(DragEvent event) {
    Dragboard dragboard = event.getDragboard();
    if (dragboard.hasImage() || dragboard.hasFiles()) {
        try {
            photoImageView.setImage(new Image(new FileInputStream(dragboard.getFiles().get(0))));
        } catch (FileNotFoundException e) {
            throw new RuntimeException(e);
        }
    }
    event.consume();
}

@FXML
void imageViewDragOver(DragEvent event) {
    Dragboard dragboard = event.getDragboard();
    if (dragboard.hasImage() || dragboard.hasFiles()) {
        event.acceptTransferModes(TransferMode.COPY);
    }

    event.consume();
}

How do edit the copied code to allow the photo that has been dragged and dropped to be move again?

0

There are 0 answers