title: Tableview drag and drop a song in a row to a playlist button on the side bar javafx
body: <p>I have a javafx TableView populated with a class called Song. I have a sidebar in my border pane populated with Buttons that represent a class called Playlist.  my (currently basic) UI looks like this: 
  <img src="https://i.stack.imgur.com/UA6qX.png" alt="My UI"></p>
  
  <p>I want to make it so that if I drag a song and drop it in to one of the buttons on the left, it adds that song to the playlist. Also I have looked and searched around the internet for an answer and haven't found anything useful.  That being said, please don't link me to something. I have already tried implementing the code from the following link: <a href="http://docs.oracle.com/javase/8/javafx/events-tutorial/drag-drop.htm#CHDJFJDH" rel="nofollow noreferrer">http://docs.oracle.com/javase/8/javafx/events-tutorial/drag-drop.htm#CHDJFJDH</a> 
  If you have any suggestions please help me! thanks!</p>
  
  <p>UPDATE:
  Here's my code, my naming conventions are pretty easily understandable:</p>
  
  <pre><code>    musicTable.setOnMouseClicked(new EventHandler&lt;MouseEvent&gt;() { //click
          @Override
          public void handle(MouseEvent event) {
              if (event.getClickCount() == 2) { // double click
  
                  Song selected =   (Song)musicTable.getSelectionModel().getSelectedItem();
                  dragged = selected;
                  if (selected != null) {
                      System.out.println("select : " + selected);
  
                  }
              }
          }
      });
  
      musicTable.setOnDragDetected(new EventHandler&lt;MouseEvent&gt;() { //drag
          @Override
          public void handle(MouseEvent event) {
              // drag was detected, start drag-and-drop gesture
              Song selected = (Song)musicTable.getSelectionModel().getSelectedItem();
              dragged = selected;
              if (selected != null) {
  
                  Dragboard db = musicTable.startDragAndDrop(TransferMode.ANY);
                  ClipboardContent content = new ClipboardContent();
                  content.putString(selected.pointer.toString());
                  db.setContent(content);
                  event.consume();
              }
          }
      });
  
      musicTable.setOnDragOver(new EventHandler&lt;DragEvent&gt;() {
          @Override
          public void handle(DragEvent event) {
              // data is dragged over the target
              Dragboard db = event.getDragboard();
              if (event.getDragboard().hasString()) {
                  event.acceptTransferModes(TransferMode.COPY_OR_MOVE);
              }
              event.consume();
          }
      });
      musicTable.setOnDragDropped(new EventHandler&lt;DragEvent&gt;() {
          @Override
          public void handle(DragEvent event) {
              Dragboard db = event.getDragboard();
              boolean success = false;
              if (event.getDragboard().hasString()) {
  
                  String text = db.getString();
                  //tableContent.add(text);
                  //musicTable.setItems(tableContent);
  
                  success = true;
              }
              event.setDropCompleted(success);
              event.consume();
          }
      });
      playlistTable.setRowFactory(cb -&gt; {
          TableRow&lt;Playlist&gt; row = new TableRow&lt;&gt;();
          row.setOnMouseClicked(ev -&gt; {
              musicTable.setItems(row.getItem().playlist);
  
              row.setOnDragDropped( new EventHandler&lt;DragEvent&gt;() {
                  @Override
                  public void handle(DragEvent event) {
                      boolean success = false;
  
                      row.getItem().add(dragged);
                      System.out.println("ACCEPED TRANSFER");
  
                      success = true;
  
                      event.setDropCompleted(success);
                      event.consume();
                  }
              });
          });
          return row;
  
      });
  </code></pre>
  
  <p>dragged is a song that keeps track of which song is being dragged, if you have any other way of doing that please tell me, musicTable is what I'm dragging from, playlist table is where I'm dragging to.</p>