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

WebView in JFXPanel does not receive Dnd events

    Details

    • Type: Bug
    • Status: Resolved
    • Priority: P4
    • Resolution: Incomplete
    • Affects Version/s: 7-pool
    • Fix Version/s: 8
    • Component/s: javafx
    • Environment:

      b45 Win7 32 bits

      Description

      Hi,
      Once a WebView is embedded in a JFXPanel it no longer receives Dnd events.
      In the following code, the setOnDragXXX() methods are never called.
      Thanks.



      {code}
      package com.labs;

      import java.awt.Dimension;

      import javafx.application.Platform;
      import javafx.embed.swing.JFXPanel;
      import javafx.event.EventHandler;
      import javafx.scene.Scene;
      import javafx.scene.input.DragEvent;
      import javafx.scene.input.Dragboard;
      import javafx.scene.input.TransferMode;
      import javafx.scene.paint.Color;
      import javafx.scene.web.WebView;

      import javax.swing.JFrame;
      import javax.swing.SwingUtilities;

      public class WebViewInJFXPanel {

      private void initAndShowGUI() {

      // This method is invoked on Swing thread
      JFrame frame = new JFrame("WebView in JFXPanel");
      frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

      final JFXPanel fxPanel = new JFXPanel();
      fxPanel.setOpaque(false);
      fxPanel.setPreferredSize(new Dimension(800,600));


      frame.add(fxPanel);
      frame.pack();
      frame.setVisible(true);

      // Init JFX
      Platform.runLater(new Runnable() {
      @Override
      public void run() {
      initFX(fxPanel);
      }
      });
      }

      private void initFX(JFXPanel fxPanel) {
      // This method is invoked on JavaFX thread
      WebView webView = new WebView();
      webView.getEngine().load("http://javafx.com");

      // The following triggers are never invoked once in a JFXPanel
      webView.setOnDragEntered(new EventHandler<DragEvent>() {

      public void handle(DragEvent event) {
      System.err.println(event.toString());
      }
      });
      webView.setOnDragOver(new EventHandler<DragEvent>() {
      @Override
      public void handle(DragEvent event) {
      System.err.println(event.toString());
      Dragboard db = event.getDragboard();
      if (db.hasString()) {
      event.acceptTransferModes(TransferMode.COPY_OR_MOVE);
      }
      event.consume();
      }
      });
      webView.setOnDragDropped(new EventHandler<DragEvent>() {
      @Override
      public void handle(DragEvent event) {
      System.err.println(event.toString());
      Dragboard db = event.getDragboard();
      boolean success = false;
      if (db.hasString()) {
      System.out.println("Dropped: " + db.getString());
      success = true;
      }
      event.setDropCompleted(success);
      event.consume();
      }
      });

      Scene scene = new Scene(webView, 800, 650, Color.BLACK);
      scene.setFill(Color.BLACK);
      fxPanel.setScene(scene);
      }

      public static void main(String[] args) {

      SwingUtilities.invokeLater(new Runnable() {
      @Override
      public void run() {
      new WebViewInJFXPanel().initAndShowGUI();
      }
      });
      }
      }
      {code}

        Attachments

          Activity

            People

            • Assignee:
              art Artem Ananiev
              Reporter:
              anouardjfx arnaud nouard (Inactive)
            • Votes:
              0 Vote for this issue
              Watchers:
              0 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved:
                Imported: