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

Drag and Drop not working in mix mode (JavaFX / Swing)

XMLWordPrintable

    • x86
    • other

      FULL PRODUCT VERSION :
      java version "9"
      Java(TM) SE Runtime Environment (build 9+181)
      Java HotSpot(TM) 64-Bit Server VM (build 9+181, mixed mode)

      ADDITIONAL OS VERSION INFORMATION :
      Microsoft Windows [Version 10.0.15063]

      A DESCRIPTION OF THE PROBLEM :
      DnD does not work in mixed mode.

      In the example here, nothing happens when running as a JavaFX application. When running as a Swing application, the drag is initiated as expected.

      Using the source code in https://bugs.openjdk.java.net/browse/JDK-8094457, yields a different result, the drag gesture is recognized but doesn't do anything. However, trying a second time causes an exception:
      Exception in thread "JavaFX Application Thread" java.awt.dnd.InvalidDnDOperationException: Drag and drop in progress
      at java.desktop/sun.awt.dnd.SunDragSourceContextPeer.setDragDropInProgress(SunDragSourceContextPeer.java:357)
      at java.desktop/java.awt.dnd.DragSource.startDrag(DragSource.java:303)
      at java.desktop/java.awt.dnd.DragSource.startDrag(DragSource.java:422)
      at java.desktop/java.awt.dnd.DragGestureEvent.startDrag(DragGestureEvent.java:238)
      at dsi.SwingDnD$2$1.dragGestureRecognized(SwingDnD.java:78)
      [snip]



      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      In the program, set the testFX variable in the main() method to false. This will run it in Swing. The drag starts correctly.
      Change the testFX variable to true and try again; this time the drag will not be initiated.

      Also try the code in https://bugs.openjdk.java.net/browse/JDK-8094457. Here, the bug will manifest itself as a java.awt.dnd.InvalidDnDOperationException



      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      Drag and Drop to work as it did
      ACTUAL -
      Nothing happens

      REPRODUCIBILITY :
      This bug can be reproduced always.

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

      import java.awt.GridLayout;
      import javafx.application.Application;
      import javafx.embed.swing.SwingNode;
      import javafx.scene.Scene;
      import javafx.scene.layout.StackPane;
      import javafx.stage.Stage;

      import java.awt.event.ActionEvent;
      import java.awt.event.ActionListener;

      import javax.swing.JButton;
      import javax.swing.JFrame;
      import javax.swing.JPanel;
      import javax.swing.JTextField;
      import javax.swing.SwingUtilities;

      public class SwingFx extends Application {

      @Override
      public void start(Stage stage) {
      final SwingNode swingNode = new SwingNode();

      createSwingContent(swingNode);

      StackPane pane = new StackPane();
      pane.getChildren().add(swingNode);

      stage.setTitle("JavaFX Sample App");
      stage.setScene(new Scene(pane, 800, 600));
      stage.show();
      }
      private static JPanel createPanel() {
      JButton button = new JButton("Click Here!");
      JTextField field = new JTextField("Text");
      field.setDragEnabled(true);
      button.addActionListener(new ActionListener() {

      @Override
      public void actionPerformed(ActionEvent e) {
      System.out.println("Button Clicked!!!");
      }
      });
      JPanel p = new JPanel(new GridLayout(1, 2));
      p.add(button);
      p.add(field);
      return p;
      }

      private void createSwingContent(final SwingNode swingNode) {
      SwingUtilities.invokeLater(new Runnable() {
      @Override
      public void run() {
      swingNode.setContent(createPanel());
      }
      });
      }
      public static void main(String[] args) {
      boolean testFX = true;

      if (testFX)
      Application.launch(SwingFx.class, args);
      else {
      SwingUtilities.invokeLater(() -> {
      JFrame frame = new JFrame();
      frame.setSize(200, 200);
      frame.setContentPane(createPanel());
      frame.setVisible(true);
      });
      }
      }
      }

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

            psadhukhan Prasanta Sadhukhan
            webbuggrp Webbug Group
            Votes:
            0 Vote for this issue
            Watchers:
            7 Start watching this issue

              Created:
              Updated:
              Resolved: