title: JavaFX drag and drop not working correctly
body: <p>Im doing a drag and drop test with two Imageviews in a gridpane. My problem is that when i complete the drag and drop and move target imageview to source imageview and release the mouse i wrongly end up with it showing the picture from "img2" and not the picture from "img1". When i comment out the "setOnDragExited" method i end up with the correct image "img1" Any suggestions would be appreciated.</p>
  
  <pre><code>import javafx.application.Application;
  import javafx.event.EventHandler;
  import javafx.scene.Scene;
  import javafx.scene.image.Image;
  import javafx.scene.image.ImageView;
  import javafx.scene.input.*;
  import javafx.scene.layout.GridPane;
  import javafx.scene.paint.Color;
  import javafx.stage.Stage;
  
  public class Test extends Application
  {
  Image img1 = new Image("/graphics/hvid/hvidBonde.png");
  Image hvidTom = new Image("/graphics/hvid/hvidTom.png");
  Image sortTom = new Image("/graphics/sort/sortTom.png");
  ImageView source = new ImageView(img1);
  Image img2 = new Image("/graphics/sort/sortBonde.png");
  ImageView target = new ImageView(img2);
  
  GridPane root = new GridPane();
  
  @Override
  public void start(Stage primaryStage) throws Exception
  {
  
      root.add(source, 1, 1);
      root.add(target, 2, 2);
  
      Scene scene = new Scene(root, 800, 800, Color.WHITE);
      primaryStage.setScene(scene);
      primaryStage.setResizable(false);
      primaryStage.show();
  
      source.setOnDragDetected(new EventHandler&lt;MouseEvent&gt;() {
          public void handle(MouseEvent event)
          {
              Dragboard db = source.startDragAndDrop(TransferMode.MOVE);
              ClipboardContent content = new ClipboardContent();
              content.putString(source.toString());
              db.setContent(content);
              event.consume();
          }
      });
  
      target.setOnDragOver(new EventHandler&lt;DragEvent&gt;() {
          public void handle(DragEvent event) {
              if (event.getGestureSource() != target &amp;&amp;
                      event.getDragboard().hasString())
              {
                  event.acceptTransferModes(TransferMode.MOVE);
              }
              event.consume();
          }
      });
  
      target.setOnDragEntered(new EventHandler&lt;DragEvent&gt;() {
          public void handle(DragEvent event)
          {
              if (event.getGestureSource() != target &amp;&amp;
                      event.getDragboard().hasString())
              {
                  target.setImage(source.getImage());
              }
              event.consume();
          }
      });
  
      target.setOnDragExited(new EventHandler&lt;DragEvent&gt;()
      {
          public void handle(DragEvent event)
          {
              target.setImage(img2);
              event.consume();
          }
      });
  
      target.setOnDragDropped(new EventHandler&lt;DragEvent&gt;() {
          public void handle(DragEvent event)
          {
              Dragboard db = event.getDragboard();
              boolean success = false;
              if (db.hasString())
              {
                  target.setImage(source.getImage());
                  success = true;
              }
              event.setDropCompleted(success);
              event.consume();
          }
      });
  
      source.setOnDragDone(new EventHandler&lt;DragEvent&gt;() {
          public void handle(DragEvent event)
          {
              if (event.getTransferMode() == TransferMode.MOVE)
              {
  
                  source.setImage(hvidTom);
  
              }
              event.consume();
          }
      });
  }
  
  }
  </code></pre>