Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8128384

Mac: DragAndDrop: file transfer issue on MacOS

XMLWordPrintable

      DragOver/DragDropped events are not received after putting file data into dragboard on Mac. Sample to reproduce:

      public class Main extends Application {

          Pane group;

          public static void main(String[] args) {
              launch(args);
          }

          private Parent getContent() {
              VBox list = new VBox(10);

              final Button btn = new Button("Button");

              list.getChildren().add(btn);

              btn.setOnDragDetected(new EventHandler<MouseEvent>() {

                  @Override
                  public void handle(MouseEvent t) {
                      System.out.println("OnDragDetected");

                      Dragboard db = btn.startDragAndDrop(TransferMode.MOVE);
                      System.out.println("Transfer modes: " + db.getTransferModes());
                      ClipboardContent cont = new ClipboardContent();
                      List<File> fl = new LinkedList<File>();
                      fl.add(new File("tmp.txt"));
                      cont.putFiles(fl);
                      db.setContent(cont);
                      t.consume();
                  }
              });

              btn.setOnDragOver(new EventHandler<DragEvent>() {
                  @Override
                  public void handle(DragEvent t) {
                      System.out.println("OnDragOver");
                      t.acceptTransferModes(TransferMode.ANY);
                  }
              });

              btn.setOnDragDropped(new EventHandler<DragEvent>() {
                  @Override
                  public void handle(DragEvent t) {
                      System.out.println("OnDragDropped");
                      t.setDropCompleted(true);
                  }
              });


              return list;
          }

          public void start(Stage stage) {
              stage.setX(100);
              stage.setY(100);
              stage.setWidth(300);
              stage.setHeight(300);
              Scene scene = new Scene(group = new VBox());
              group.getChildren().add(getContent());
              group.getChildren().add(getContent());
              stage.setScene(scene);
              stage.show();

          }
      }

            morris Morris Meyer (Inactive)
            ogb Oleg Barbashov (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported: