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

Mac: DragAndDrop: Dragging files to the finder does not work

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Fixed
    • Icon: P4 P4
    • 8
    • 7u15, 8
    • javafx
    • Mac OS X 10.8.3, JavaFX 2.2.7-b01, JavaFX 8.0.0-ea-b82

      We want to drag a java.io.File from our JavaFX application to the Mac OS X finder or desktop. But no matter what we try the dragged File is not accepted (little stop sign on the dragged image).

      It works on Ubuntu and Windows XP.

      We put the Files into the ClipboardContent using clipboardContent.putFiles(). There is an example attached as well.

      If we output the ContentTypes of the Dragboard we get an additionally [placeholder.custom.bytes] entry:

      System.out.println(t.getDragboard().getContentTypes()):
      [[placeholder.custom.bytes], [application/x-java-file-list, java.file-list]]

      We wonder if this might be the cause that Mac OS X gets confused or something.

      SSCCE attached:

      import javafx.application.Application;
      import javafx.event.EventHandler;
      import javafx.geometry.Insets;
      import javafx.scene.Scene;
      import javafx.scene.control.Button;
      import javafx.scene.input.ClipboardContent;
      import javafx.scene.input.DragEvent;
      import javafx.scene.input.Dragboard;
      import javafx.scene.input.MouseEvent;
      import javafx.scene.input.TransferMode;
      import javafx.scene.layout.VBox;
      import javafx.stage.Stage;

      import java.io.File;
      import java.util.Arrays;

      public class Main extends Application {
          public static void main(String[] args) {
              launch(args);
          }

          public void start(final Stage stage) {
              final Button button = new Button("Drag me or drop files on me");
              button.setOnDragDetected(new EventHandler<MouseEvent>() {
                  @Override
                  public void handle(MouseEvent t) {
                      System.out.println("OnDragDetected");

                      ClipboardContent clipboardContent = new ClipboardContent();
                      clipboardContent.putFiles(Arrays.asList(new File("/Users/jenshohmuth/Desktop/scenicView.properties"))); // FIXME YOU MIGHT WANNA CHANGE THAT FILE TO SOME OTHER EXISTING FILE

                      Dragboard dragboard = button.startDragAndDrop(TransferMode.COPY);
                      System.out.println("Transfer modes: " + dragboard.getTransferModes());
                      dragboard.setContent(clipboardContent);

                      t.consume();
                  }
              });

              button.setOnDragOver(new EventHandler<DragEvent>() {
                  @Override
                  public void handle(DragEvent t) {
                      System.out.println("OnDragOver");
                      System.out.println(t.getDragboard().getContentTypes());
                      System.out.println(t.getDragboard().getFiles());
                  }
              });

              VBox group = new VBox();
              group.setPadding(new Insets(10));
              group.getChildren().add(button);

              Scene scene = new Scene(group);
              stage.setScene(scene);
              stage.show();
          }
      }

            pchelko Petr Pchelko (Inactive)
            jhohmuthjfx Jens Hohmuth (Inactive)
            Votes:
            1 Vote for this issue
            Watchers:
            4 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported: