title: JavaFX How to drag and drop an image
body: <p>I am making a card game in JavaFX and what I was able to find code that will allow me to drag a piece of text. However, this doesn't show the text being dragged. </p>
  
  <p>What I am currently doing is setting my scene which is the root node to be the target and setting my cards to be the source. This allows me to drag cards which are image views on my desktop but I want two things which I am struggling with.</p>
  
  <p>First I want to have the image actually show up when I am dragging it and second I want to be able to place the image on my scene.</p>
  
  <p>Here is the code for the card</p>
  
  <pre><code>        tempImageView.setOnDragDetected(new EventHandler&lt;MouseEvent&gt;() {
              public void handle(MouseEvent event) {
                  /* drag was detected, start a drag-and-drop gesture*/
                  /* allow any transfer mode */
                  Dragboard db = 
   tempImageView.startDragAndDrop(TransferMode.ANY);
  
                  /* Put a string on a dragboard */
                  ClipboardContent content = new ClipboardContent();
                  content.putData(tempImageView);
                  db.setContent(content);
  
                  event.consume();
              }
          });
  </code></pre>
  
  <p>Here is the code for my scene</p>
  
  <pre><code>    scene.setOnDragOver(new EventHandler&lt;DragEvent&gt;() {
          public void handle(DragEvent event) {
              /* data is dragged over the target */
              /* accept it only if it is not dragged from the same node 
               * and if it has a string data */
              /* allow for both copying and moving, whatever user chooses */
              event.acceptTransferModes(TransferMode.COPY_OR_MOVE);
              event.consume();
          }
      });
  </code></pre>
  
  <p>Here is the tutorial I was trying to follow: <a href="https://docs.oracle.com/javafx/2/drag_drop/jfxpub-drag_drop.htm" rel="nofollow noreferrer">https://docs.oracle.com/javafx/2/drag_drop/jfxpub-drag_drop.htm</a></p>
  
  <p>I am new to JavaFX so any help would be awesome!</p>