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

Drag and drop inconsistent behavior.

    XMLWordPrintable

Details

    • Bug
    • Resolution: Not an Issue
    • P3
    • None
    • 8
    • javafx
    • jdk 1.8.0-b61, MacOS X 10.7.4

    Description

      Test case:

      Input:
      Drag source - button "Source"; Drag target - button "Destination".
      onDragDetected event puts a string to the clipboard and transferMode is COPY.
      Target doesn't support any transfer modes.

      Expected outcome:
      Target would never receive "onDragDropped" event. Source would never receive "onDragDone" event.

      Actual outcome:
      Target hasn't received "onDragDropped" event.
      But source have received "onDragDone" event.

      To reproduce drag "Source" button to "Destination".

      import javafx.application.Application;
      import javafx.event.EventHandler;
      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.HBox;
      import javafx.stage.Stage;

      public class TestDND extends Application {

          @Override
          public void start(Stage stage) {

              //Set up source
              final Button source = new Button("Source");
              
              source.setOnDragDetected(new EventHandler<MouseEvent>() {
                  @Override
                  public void handle(MouseEvent t) {
                      Dragboard db = source.startDragAndDrop(TransferMode.COPY);

                      ClipboardContent content = new ClipboardContent();
                      content.putString(source.getText());
                      db.setContent(content);

                      t.consume();
                  }
              });

              source.setOnDragDone(new EventHandler<DragEvent>() {
                  @Override
                  public void handle(DragEvent t) {
                      System.out.println("onDragDone");
                  }
              });
              
              //Set up target
              final Button target = new Button("Destination");

              target.setOnDragOver(new EventHandler<DragEvent>() {
                  @Override
                  public void handle(DragEvent t) {
                      System.out.println("Accepted mode = " + t.getAcceptedTransferMode());
                      t.consume();
                  }
              });

              target.setOnDragDropped(new EventHandler<DragEvent>() {
                  @Override
                  public void handle(DragEvent t) {
                      System.out.println("onDragDroppped");
                      boolean result = false;
                      
                      if (t.getGestureSource() != target &&
                              t.getDragboard().hasString()) {
                          System.out.println("Accepted string: " + t.getDragboard().getString());
                          result = true;
                      }
                      System.out.println("result = " + result);
                      t.setDropCompleted(result);
                      t.consume();
                  }
              });

              HBox root = new HBox(10d);
              root.getChildren().addAll(source, target);
              Scene scene = new Scene(root, 300, 250);

              stage.setScene(scene);
              stage.setTitle(System.getProperty("java.runtime.version") + "; " + System.getProperty("javafx.runtime.version"));
              stage.show();
          }

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

      Attachments

        Activity

          People

            psafrata Pavel Ĺ afrata
            dzinkevi Dmitry Zinkevich (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:
              Imported: