Example usage for javafx.scene.control TextField setOnDragDropped

List of usage examples for javafx.scene.control TextField setOnDragDropped

Introduction

In this page you can find the example usage for javafx.scene.control TextField setOnDragDropped.

Prototype

public final void setOnDragDropped(EventHandler<? super DragEvent> value) 

Source Link

Usage

From source file:fr.amap.lidar.amapvox.gui.MainFrameController.java

private void setDragDroppedSingleFileEvent(final TextField textField) {

    textField.setOnDragDropped(new EventHandler<DragEvent>() {
        @Override//from   ww w.  j  a  v  a2  s .  com
        public void handle(DragEvent event) {
            Dragboard db = event.getDragboard();
            boolean success = false;
            if (db.hasFiles() && db.getFiles().size() == 1) {
                success = true;
                for (File file : db.getFiles()) {
                    if (file != null) {
                        textField.setText(file.getAbsolutePath());
                    }
                }
            }
            event.setDropCompleted(success);
            event.consume();
        }
    });
}