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

Drag and drop isDropCompleted and getTransferMode don't seem to be working

    Details

    • Type: Bug
    • Status: Closed
    • Priority: P4
    • Resolution: Duplicate
    • Affects Version/s: 7u6
    • Fix Version/s: 8
    • Component/s: javafx
    • Labels:
    • Environment:

      OSX, Linux, Windows XP, Java 7 update 11

      Description

      Run the program below and drag the Source Label to anywhere but the Target Label. This is the output:

      Drag Done
      Drop Completed: false
      Transfer Mode: COPY

      getTransferMode is returning COPY even though the api says that in the case where no data has been transferred, null is returned.

      Now drag the Source Label to the Target Label and drop it there. This is the output:

      Drag Done
      Drop Completed: false
      Transfer Mode: COPY

      isDropCompleted is returning false but I expect it to return true.

      This is on OSX. I don't think it works on Linux either in a different way. I will post a comment tomorrow detailing that.

      -----------EDIT-------------------
      OK, I've tested on Linux as well. In the case where you drop over anything but the Target Label you get this output:

      Drag Done
      Drop Completed: false
      Transfer Mode: null

      which is correct. However, when you drop over the Target Label you get this output:

      Drag Done
      Drop Completed: false
      Transfer Mode: COPY

      which is incorrect as drag completed should be true.

      So not only do I think the isDropCompleted and getTransferMode methods are returning the incorrect results under certain circumstances, I also think they are different between platforms. This is definitely wrong.
      -------------------------------------
      Another EDIT

      Just tested on Windows. Behaves the same as Linux. i.e. correct when dropping anywhere but the Target Label, but "Drop Completed: false" when dropping over the Target Label. I think this method should return true when dropped over the target label as I set it to true: dragEvent.setDropCompleted(true);
      -------------------------------------


      import javafx.event.EventHandler;
      import javafx.scene.Scene;
      import javafx.scene.control.Label;
      import javafx.scene.input.*;
      import javafx.scene.layout.BorderPane;
      import javafx.stage.Stage;

      public class DragAndDropTest extends javafx.application.Application {
          @Override
          public void start(Stage stage) throws Exception {
              BorderPane borderPane = new BorderPane();
              Scene scene = new Scene(borderPane, 500, 500);

              final Label sourceLabel = new Label("Source Label");
              final Label targetLabel = new Label("Target Label");

              sourceLabel.setOnDragDetected(new EventHandler<MouseEvent>() {
                  @Override
                  public void handle(MouseEvent mouseEvent) {
      // System.out.println("Drag Detected");
                      Dragboard db = sourceLabel.startDragAndDrop(TransferMode.ANY);
                      ClipboardContent content = new ClipboardContent();
                      content.putString(sourceLabel.getText());
                      db.setContent(content);
                      mouseEvent.consume();
                  }
              });

              sourceLabel.setOnDragDone(new EventHandler<DragEvent>() {
                  @Override
                  public void handle(DragEvent dragEvent) {
                      System.out.println("Drag Done");
                      boolean dropCompleted = dragEvent.isDropCompleted();
                      System.out.println("Drop Completed: " + dropCompleted);
                      TransferMode transferMode = dragEvent.getTransferMode();
                      System.out.println("Transfer Mode: " + transferMode);
                      if (dropCompleted) {
                          sourceLabel.setText("Moved");
                      }
                      dragEvent.consume();
                  }
              });

              targetLabel.setOnDragOver(new EventHandler<DragEvent>() {
                  @Override
                  public void handle(DragEvent dragEvent) {
      // System.out.println("Drag Over");
                      if (dragEvent.getGestureSource() != targetLabel &&
                              dragEvent.getDragboard().hasString()) {
                          dragEvent.acceptTransferModes(TransferMode.COPY_OR_MOVE);
                      }
                      dragEvent.consume();
                  }
              });

              targetLabel.setOnDragDropped(new EventHandler<DragEvent>() {
                  @Override
                  public void handle(DragEvent dragEvent) {
      // System.out.println("Drag Dropped");
                      Dragboard db = dragEvent.getDragboard();
                      boolean success = false;
                      if (db.hasString()) {
                          targetLabel.setText(db.getString());
                          success = true;
                      }
                      dragEvent.setDropCompleted(success);
                      dragEvent.consume();
                  }
              });

              borderPane.setLeft(sourceLabel);
              borderPane.setRight(targetLabel);

              stage.setScene(scene);
              stage.show();
          }

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

        Attachments

          Issue Links

            Activity

              People

              • Assignee:
                pchelko Petr Pchelko (Inactive)
                Reporter:
                ndarcy Nick D'Arcy
              • Votes:
                0 Vote for this issue
                Watchers:
                3 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved:
                  Imported: