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

Drag and Drop getting stuck after mouse clicked on button

XMLWordPrintable

      ADDITIONAL SYSTEM INFORMATION :
      Linux Mint 20.3 Cinnamon 64 bit
      libgtk-3-0:amd64 3.24.20-0ubuntu1.1

      A DESCRIPTION OF THE PROBLEM :
      This bug is caused by simply clicking on the button (normal click: press and release). Afterwards JFX is stuck in DnD even though the mouse is released. No events seem to be dispatched anymore. Sometimes only pressing ESC key helps.

      The buttons MOUSE_PRESSED handler calls event.setDragDetect(true) and the DRAG_DETECTED handler prepares the Dragboard.


      ---------- BEGIN SOURCE ----------

      import javafx.application.Application;
      import javafx.scene.Scene;
      import javafx.scene.control.Button;
      import javafx.scene.input.ClipboardContent;
      import javafx.scene.input.Dragboard;
      import javafx.scene.input.TransferMode;
      import javafx.scene.layout.VBox;
      import javafx.stage.Stage;

      public class PressDrag extends Application
      {

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

        @Override
        public void start(Stage primaryStage) throws Exception
        {
          primaryStage.setTitle("Hello World!");
          VBox box = new VBox();
          box.setOnDragOver(e -> System.out.println("still dragging"));
          
          Button btn = new Button("simply click here");
          btn.setOnMousePressed(event ->
          {
            event.setDragDetect(true);
          });
          btn.setOnDragDetected(event ->
          {
            Dragboard db = btn.startDragAndDrop(TransferMode.MOVE);
            ClipboardContent content = new ClipboardContent();
            content.putString("bla");
            db.setContent(content);
          });
          btn.setOnDragDropped(e -> System.out.println("dropped on button"));
          
          box.getChildren().add(btn);

          primaryStage.setScene(new Scene(box, 300, 250));
          primaryStage.show();
        }

      }

      ---------- END SOURCE ----------

      FREQUENCY : always


            pnarayanaswa Praveen Narayanaswamy
            webbuggrp Webbug Group
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: