title: how to copy selected items from listview to textarea by drag and drop
body: <p>Something is wrong in my simple application. I tried to copy selected items from listview to textarea by drag and drop, but I guess I did make a fault with the handling of 'drag detected'.
  No text is dropped. When dragging text from an editor it is dropped in the textarea.</p>
  <p>Thanks for your help!</p>
  <p>This is the code.</p>
  <pre><code>public class Main extends Application {
  public static void main(String[] args) {
      launch(args);
  }
  
  @Override
  public void start(Stage stage) {
      BorderPane borderPane = new BorderPane();
      TextArea textArea = new TextArea(&quot;my textarea\n&quot;);
      ListView&lt;String&gt; listView = new ListView&lt;&gt;(FXCollections.observableArrayList(
              &quot;Julia&quot;, &quot;Ian&quot;, &quot;Sue&quot;, &quot;Matthew&quot;, &quot;Hannah&quot;, &quot;Stephan&quot;, &quot;Denise&quot;));
      listView.getSelectionModel().setSelectionMode(SelectionMode.MULTIPLE);
      listView.setOrientation(Orientation.HORIZONTAL);
      listView.setPrefHeight(50.0);
  
      textArea.setOnDragOver(dragEvent -&gt; {
          if (dragEvent.getDragboard().hasString()) dragEvent.acceptTransferModes(TransferMode.COPY);
          dragEvent.consume();
      });
  
      textArea.setOnDragDropped(dragEvent -&gt; {
          Dragboard db = dragEvent.getDragboard();
          boolean success = false;
          if (db.hasString()) {
              textArea.appendText(db.getString());
              success = true;
          }
          dragEvent.setDropCompleted(success);
          dragEvent.consume();
      });
  
      listView.setOnDragDetected(dragEvent -&gt; {
          StringBuilder sb = new StringBuilder(&quot;my selection: &quot;);
          Dragboard dragboard = listView.startDragAndDrop(TransferMode.COPY);
          ClipboardContent content = new ClipboardContent();
          listView.getSelectionModel().getSelectedItems().forEach(item -&gt; {
              sb.append(&quot;\t&quot;);
              sb.append(item);
          });
          content.putString(sb.toString());
          dragboard.setContent(content);
          if (dragboard.hasContent(DataFormat.PLAIN_TEXT)) System.out.println(content);
          dragEvent.consume();
      });
      borderPane.setTop(listView);
      borderPane.setCenter(textArea);
  
      Scene scene = new Scene(borderPane, 500, 250);
      stage.setTitle(&quot;Drag &amp; Drop&quot;);
      stage.setScene(scene);
      stage.show();
  }
  </code></pre>
  <p>}</p>
  <hr />
  <p>@Slaw, thanks for your comment. Now I have tested the application at Ubuntu and Windows10.</p>
  <p>Ubuntu</p>
  <pre><code>     java -version
       openjdk version &quot;11.0.7&quot; 2020-04-14
       OpenJDK Runtime Environment (build 11.0.7+10-post-Ubuntu-2ubuntu218.04)
       OpenJDK 64-Bit Server VM (build 11.0.7+10-post-Ubuntu-2ubuntu218.04, mixed mode, sharing)
  </code></pre>
  <p>Windows10</p>
  <pre><code>    java -version
      openjdk version &quot;12.0.2&quot; 2019-07-16
      OpenJDK Runtime Environment (build 12.0.2+10)
      OpenJDK 64-Bit Server VM (build 12.0.2+10, mixed mode, sharing)
  </code></pre>
  <p>The code works with Windows10, but not with Ubuntu. Therefore I think it's correct. But I don't know where I can find the cause for the problem at Ubuntu.</p>