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

Mac: Drag and drop of files not working

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Resolved
    • Priority: P4
    • Resolution: Fixed
    • Affects Version/s: fx2.1
    • Fix Version/s: fx2.1
    • Component/s: javafx
    • Labels:
    • Environment:

      Mac OS X 10.7.2, JavaFX 2.1 beta b05, Java 1.6.0_29

      Description

      When the following application is run under Mac OS X, DRAG_DROPPED never appears in the output. The output consists only of DRAG_OVER events:

      ===== DRAG_OVER =====
      system mode: null
      source modes: []
      accepted modes: null
      WARNING: unhandled case in mapNsOperationToJavaMask: 0 [on thread "0x0x7fff7adb3960", is main:1]
      ===== DRAG_OVER =====
      system mode: null
      source modes: []
      accepted modes: null
      WARNING: unhandled case in mapNsOperationToJavaMask: 0 [on thread "0x0x7fff7adb3960", is main:1]

      etc.

      On Windows with the latest JavaFX 2.0.2, the output is as expected:

      ===== DRAG_OVER =====
      system mode: MOVE
      source modes: [COPY, MOVE, LINK]
      accepted modes: MOVE
      ===== DRAG_OVER =====
      system mode: MOVE
      source modes: [COPY, MOVE, LINK]
      accepted modes: MOVE
      ===== DRAG_DROPPED =====
      Dropped: [C:\Users\Dean Iverson\Documents\ca\DragDrop2.jar]

      The code is as follows:

      public class DragDrop1 extends Application {

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

        @Override
        public void start(Stage primaryStage) {
          Rectangle rect = new Rectangle(100, 100);
          rect.setId("dragTarget");

          rect.setOnDragOver(new EventHandler<DragEvent>() {
            @Override
            public void handle(DragEvent event) {
              System.out.println("===== DRAG_OVER =====");
              System.out.println("system mode: "+event.getTransferMode());
              Dragboard db = event.getDragboard();
              System.out.println("source modes: "+db.getTransferModes());
              if (db.hasFiles()) {
                event.acceptTransferModes(TransferMode.ANY);
                System.out.println("accepted modes: "+event.getAcceptedTransferMode());
              }
              event.consume();
            }
          });

          rect.setOnDragDropped(new EventHandler<DragEvent>() {
            @Override
            public void handle(DragEvent event) {
              System.out.println("===== DRAG_DROPPED =====");
              Dragboard db = event.getDragboard();
              boolean success = false;
              if (db.hasFiles()) {
                System.out.println("Dropped: " + db.getFiles());
                success = true;
              }
              event.setDropCompleted(success);
              event.consume();
            }
          });
          
          final StackPane root = new StackPane();
          root.getChildren().add(rect);
          
          final Scene scene = new Scene(root);
          final URL stylesheet = getClass().getResource("media.css");
          scene.getStylesheets().add(stylesheet.toString());
          
          primaryStage.setScene(scene);
          primaryStage.setTitle("Audio Player 2");
          primaryStage.show();
        }
      }

        Attachments

          Issue Links

            Activity

              People

              Assignee:
              morris Morris Meyer (Inactive)
              Reporter:
              diversonjfx Dean Iverson (Inactive)
              Votes:
              0 Vote for this issue
              Watchers:
              4 Start watching this issue

                Dates

                Created:
                Updated:
                Resolved:
                Imported: