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

DnD doesn't work for JFXPanel

    Details

    • Subcomponent:
    • CPU:
      x86_64
    • OS:
      windows_7

      Description

      FULL PRODUCT VERSION :
      java version "1.8.0_65"
      Java(TM) SE Runtime Environment (build 1.8.0_65-b17)
      Java HotSpot(TM) 64-Bit Server VM (build 25.65-b01, mixed mode)

      ADDITIONAL OS VERSION INFORMATION :
      Microsoft Windows [Version 6.1.7601]

      A DESCRIPTION OF THE PROBLEM :
      We have a swing application. It uses JFXPanel to embed some JavaFX components (mainly WebView). When we drag something from swing or an external application and try to drop on a JavaFX component inside the JFXPanel, it doesn't accept the drop.

      REGRESSION. Last worked in version 7u76

      ADDITIONAL REGRESSION INFORMATION:
      java version "1.7.0"
      Java(TM) SE Runtime Environment (build 1.7.0-b147)
      Java HotSpot(TM) 64-Bit Server VM (build 21.0-b17, mixed mode)

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      Run the sample application drag the "Drag me" label and try to drop it in the second text box.

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      The text box excepts the drop.
      ACTUAL -
      The text box doesn't except the drop.

      REPRODUCIBILITY :
      This bug can be reproduced always.

      ---------- BEGIN SOURCE ----------
      import javafx.application.Platform;
      import javafx.embed.swing.JFXPanel;
      import javafx.scene.Scene;
      import javafx.scene.control.TextField;
      import javafx.scene.layout.HBox;
      import javafx.scene.layout.Priority;

      import javax.swing.*;

      import java.awt.FlowLayout;
      import java.awt.Point;
      import java.awt.datatransfer.StringSelection;
      import java.awt.datatransfer.Transferable;
      import java.awt.dnd.DnDConstants;
      import java.awt.dnd.DragSource;
      import java.awt.event.MouseAdapter;
      import java.awt.event.MouseEvent;

      public class DnDTest {

        public static void main(final String... pArguments) {
          SwingUtilities.invokeLater(new Runnable() {
            @Override
            public void run() {
              JFrame frame = new JFrame("DnDTest");
              frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);

              JRootPane rootPane = frame.getRootPane();
              rootPane.setLayout(new FlowLayout());
              JLabel label = new JLabel("Drag me");
              label.setTransferHandler(new TransferHandler() {
                @Override
                protected Transferable createTransferable(final JComponent pComponent) {
                  return new StringSelection("Drag text");
                }

                @Override
                public int getSourceActions(final JComponent pComponent) {
                  return DnDConstants.ACTION_COPY;
                }
              });
              MouseAdapter dragGestureRecognizer = new MouseAdapter() {
                private Point mPoint;

                @Override
                public void mousePressed(MouseEvent pEvent) {
                  mPoint = pEvent.getPoint();
                }

                @Override
                public void mouseReleased(MouseEvent pEvent) {
                  mPoint = null;
                }

                @Override
                public void mouseDragged(MouseEvent pEvent) {
                  if (mPoint == null) {
                    mPoint = pEvent.getPoint();
                  }
                  double distance = pEvent.getPoint().distance(mPoint);
                  if (distance > DragSource.getDragThreshold()) {
                    JComponent component = (JComponent) pEvent.getComponent();
                    TransferHandler transferHandler = component.getTransferHandler();
                    transferHandler.exportAsDrag(component, pEvent, DnDConstants.ACTION_COPY);
                  }
                }
              };
              label.addMouseListener(dragGestureRecognizer);
              label.addMouseMotionListener(dragGestureRecognizer);
              rootPane.add(label);
              rootPane.add(new JTextField("Drop works here"));

              final JFXPanel panel = new JFXPanel();
              Platform.runLater(new Runnable() {
                @Override
                public void run() {
                  TextField textField = new TextField("Drop doesn't work here");
                  HBox hBox = new HBox();
                  HBox.setHgrow(textField, Priority.ALWAYS);
                  Scene scene = new Scene(hBox);
                  hBox.getChildren().add(textField);
                  panel.setScene(scene);
                }
              });
              rootPane.add(panel);

              frame.setSize(500, 400);
              frame.setLocationRelativeTo(null);
              frame.setVisible(true);
            }
          });
        }
      }

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

        Attachments

          Activity

            People

            • Assignee:
              psadhukhan Prasanta Sadhukhan
              Reporter:
              webbuggrp Webbug Group
            • Votes:
              0 Vote for this issue
              Watchers:
              6 Start watching this issue

              Dates

              • Created:
                Updated: