import java.awt.image.BufferedImage; import javafx.application.Application; import javafx.geometry.Orientation; import javafx.scene.Scene; import javafx.scene.control.Label; import javafx.scene.control.Separator; import javafx.scene.image.Image; import javafx.scene.image.ImageView; import javafx.scene.input.ClipboardContent; import javafx.scene.input.DragEvent; import javafx.scene.input.Dragboard; import javafx.scene.input.MouseEvent; import javafx.scene.input.TransferMode; import javafx.scene.layout.HBox; import javafx.scene.layout.VBox; import javafx.stage.Stage; /** * * @author lans */ public class DragViewFail extends Application { @Override public void start(Stage primaryStage) { Label dragMe = new Label("Drag me"); Label dragTo = new Label("Drag to"); dragMe.setPrefSize(200, 200); dragTo.setPrefSize(200, 200); Image image = new Image("http://st2.ru.oracle.com/StatusTool2/faces/resources/brand_oracle3.png"); BufferedImage customDragImg = new BufferedImage(128, 128, BufferedImage.TYPE_INT_ARGB); customDragImg.getGraphics().fillRect(0, 0, 120, 120); dragMe.setOnDragDetected((MouseEvent event) -> { Dragboard db = dragMe.startDragAndDrop(TransferMode.ANY); db.setDragView(image); ClipboardContent content = new ClipboardContent(); content.putString(dragMe.getText()); db.setContent(content); event.consume(); }); dragTo.setOnDragOver((DragEvent event) -> { if (event.getGestureSource() != dragTo && event.getDragboard().hasString()) { event.acceptTransferModes(TransferMode.COPY_OR_MOVE); dragTo.setText("Accepted"); } event.consume(); }); Scene scene = new Scene(new VBox( new HBox(dragMe, new Separator(Orientation.VERTICAL), dragTo), new ImageView(image)), 300, 400); primaryStage.setScene(scene); primaryStage.show(); } /** * @param args the command line arguments */ public static void main(String[] args) { launch(args); } }