title: JavaFX: Setting Drag Done
body: <p>Currently I am developing a program which transfers a list item into another list. It works well with <code>setOnDragExited</code>,if I drag it to another component with the <code>setOnDragExited</code>, it will be dropped. (Which I think the program is rightbecause that is the function of setOnDragExited. But I need the program to only drop the list item when I release the button).</p>
  
  <p>So I have the source which is <code>fieldList</code> and the target which is <code>mainTable</code></p>
  
  <p>Here is the code for the source, which I have no problem with.</p>
  
  <pre><code>fieldList.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 =fieldList.startDragAndDrop(TransferMode.ANY);
                  /* Put a string on a dragboard */
                  ClipboardContent content = new ClipboardContent();
                  content.putString(fieldList.getSelectionModel().getSelectedItem());
                  db.setContent(content);
  
                  event.consume();
           }
      });
  </code></pre>
  
  <p>And here is the code which doesn't work with <code>setOnDragDropped</code> but works with <code>setOnDragExited</code></p>
  
  <pre><code>mainTable.setOnDragDropped(new EventHandler&lt;DragEvent&gt;() {
               public void handle(DragEvent event) {
                   /* data dropped */
                      System.out.println("onDragDropped");
                      /* if there is a string data on dragboard, read it and use it */
                      Dragboard db = event.getDragboard();
                      boolean success = false;
                      if (db.hasString()) {
                          ObservableList&lt;String&gt; ls = FXCollections.observableArrayList(); 
  
                          try {
                              columnLS.add(Resources.getgBCon().getActualName(tableList.getSelectionModel().getSelectedItem())+"."+db.getString());
                          } catch (SQLException e) {
                              // TODO Auto-generated catch block
                              e.printStackTrace();
                          }
                          success = true;
                          String base= "";
                         if(!columnLS.isEmpty()){
                              for(int i = 0; i&lt;= columnLS.size()-1 ;i++){
                                  if(i == 0){
                                      base = columnLS.get(i);
                                  }else{
                                      base = base + ", " + columnLS.get(i);
                                  }
                              }
                          }
                          columnQuery = base;
                          me.refreshSQLQuery(columnQuery,getTableQuery(),filterQuery,groupQuery,sortQuery);
                      }
                      /* let the source know whether the string was successfully 
                       * transferred and used */
                      event.setDropCompleted(true);
  
                      event.consume();
               }
          });
  </code></pre>
  
  <p>So far I didn't find anything that relates to my problem, on those that are remotely related I found, I have tried but to no avail.
  Thank you Stack Overflow.</p>
  
  <p>I have added <code>setOnDragEntered</code>. It seems it still didn't work. Is there a difference between <code>setOnDrag</code> and <code>setOnMouseDrag</code>?</p>
  
  <pre><code>mainTable.setOnDragEntered(new EventHandler&lt;DragEvent&gt;() {
               public void handle(DragEvent event) {
                       System.out.println("onDragEntered");
                      event.acceptTransferModes(TransferMode.COPY_OR_MOVE);
               }
          });
  </code></pre>
  
  <p>I have also tried TransferMode.ANY but to no avail.</p>
  
  <p>Solution:
  Used  <code>mainTable.setOnDragOver</code> instead of <code>mainTable.setOnDragEntered</code></p>