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

Using an image with Dragboard.setDragView() on GTK3 breaks drag and drop

    XMLWordPrintable

Details

    • Bug
    • Resolution: Duplicate
    • P4
    • None
    • jfx12, jfx13
    • javafx

    Description

      ADDITIONAL SYSTEM INFORMATION :
      Linux Mint 19
      Java 12.0.1
      OpenJFX 13-ea+9

      A DESCRIPTION OF THE PROBLEM :
      After switching to OpenJFX 13-ea+9 drag and drop was working fine until I tried to set a drag image with Dragboard.setDragView(). The results were similar to the problems found with OpenJFX 12 and fixed in OpenJFX 13. See https://bugs.openjdk.java.net/browse/JDK-8211302.

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      When implementing drag and drop functionality set a drag view with Dragboard.setDragView(). Drag events stop being published consistently to drag targets.

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      Events published to the drag target consistently.
      ACTUAL -
      Events inconsistently published to drag targets.

      ---------- BEGIN SOURCE ----------
      package com.xeomar.xenon;

      import javafx.application.Application;
      import javafx.geometry.Insets;
      import javafx.scene.Cursor;
      import javafx.scene.Group;
      import javafx.scene.Scene;
      import javafx.scene.control.Label;
      import javafx.scene.image.Image;
      import javafx.scene.input.ClipboardContent;
      import javafx.scene.input.Dragboard;
      import javafx.scene.input.TransferMode;
      import javafx.scene.layout.Background;
      import javafx.scene.layout.BackgroundFill;
      import javafx.scene.layout.CornerRadii;
      import javafx.scene.paint.Color;
      import javafx.stage.Stage;

      public class DndDemo extends Application {

      @Override
      public void start( Stage stage ) {
      Group root = new Group();
      Scene scene = new Scene( root, 400, 200 );

      final Label source = new Label( "DRAG ME" );
      source.setCursor( Cursor.HAND );
      source.relocate( 50, 100 );
      source.setScaleX( 2.0 );
      source.setScaleY( 2.0 );
      source.setBackground( new Background( new BackgroundFill( Color.YELLOW, CornerRadii.EMPTY, Insets.EMPTY ) ) );

      final Label target = new Label( "DROP HERE" );
      target.relocate( 250, 100 );
      target.setScaleX( 2.0 );
      target.setScaleY( 2.0 );
      target.setBackground( new Background( new BackgroundFill( Color.GREEN, CornerRadii.EMPTY, Insets.EMPTY ) ) );

      source.setOnDragDetected( ( event ) -> {
      System.out.println( "onDragDetected" );

      Dragboard db = source.startDragAndDrop( TransferMode.MOVE );
      ClipboardContent content = new ClipboardContent();
      content.putString( "DRAGGED CONTENT" );
      db.setContent( content );

      // FIXME Using setDragView() breaks DnD on OpenJFK 13
      Image image = source.snapshot( null, null );
      db.setDragView( image, 0.5 * image.getWidth(), 0.5 * image.getHeight() );

      event.consume();
      } );

      source.setOnDragDone( ( event ) -> {
      System.out.println( "onDragDone" );

      if( event.getTransferMode() == TransferMode.MOVE ) source.setText( "" );

      event.consume();
      } );

      target.setOnDragOver( ( event ) -> {
      System.out.println( "onDragOver" );

      if( event.getGestureSource() != target && event.getDragboard().hasString() ) {
      event.acceptTransferModes( TransferMode.MOVE );
      }

      event.consume();
      } );

      target.setOnDragEntered( ( event ) -> {
      System.out.println( "onDragEntered" );

      if( event.getGestureSource() != target && event.getDragboard().hasString() ) {
      target.setTextFill( Color.WHITE );
      }

      event.consume();
      } );

      target.setOnDragExited( ( event ) -> {
      target.setTextFill( Color.BLACK );

      event.consume();
      } );

      target.setOnDragDropped( ( event ) -> {
      System.out.println( "onDragDropped" );

      Dragboard db = event.getDragboard();
      boolean hasString = db.hasString();
      if( hasString ) target.setText( db.getString() );

      event.setDropCompleted( hasString );

      event.consume();
      } );

      root.getChildren().add( source );
      root.getChildren().add( target );
      stage.setScene( scene );
      stage.show();
      }

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

      }

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

      CUSTOMER SUBMITTED WORKAROUND :
      No known workaround if a drag view is desired.

      FREQUENCY : always


      Attachments

        Issue Links

          Activity

            People

              tsayao Thiago Sayao
              webbuggrp Webbug Group
              Votes:
              0 Vote for this issue
              Watchers:
              3 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: