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

SwingNode: Ending a drag gesture should not generate an AWT mouse clicked event

    Details

    • Type: Bug
    • Status: Resolved
    • Priority: P3
    • Resolution: Fixed
    • Affects Version/s: 8
    • Fix Version/s: 8
    • Component/s: javafx
    • Labels:
    • Environment:

      Windows 7

      Description

      Tested with b117.

      When tracking the mouse events received by a JPanel contained in a SwingNode, a mouse clicked event is received at the end of a drag gesture. Here are the last events received:

      java.awt.event.MouseEvent[MOUSE_DRAGGED,(408,643)...
      java.awt.event.MouseEvent[MOUSE_RELEASED,(408,643)...
      java.awt.event.MouseEvent[MOUSE_CLICKED,(408,643)

      From the FX point of view, the Mouse Clicked event seems ok (?) but from the Swing point of view, the Mouse Clicked should not be received.

      This 'extra' event can breaks compatibility with some swing components (such as WorldWind).

      The following tests can be used to reproduce:

      import java.awt.event.MouseEvent;
      import java.awt.event.MouseListener;
      import java.awt.event.MouseMotionListener;

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

      import javax.swing.JPanel;
      import javax.swing.SwingUtilities;

      public class MouseEventFXTest extends Application {

           public MouseEventFXTest() {
           }

           @Override
           public void start(Stage primaryStage) throws Exception {
                final SwingNode swingNode = new SwingNode();
                StackPane root = new StackPane(swingNode);

                Scene scene = new Scene(root);
                primaryStage.setScene(scene);

                primaryStage.setWidth(1000);
                primaryStage.setHeight(1000);
                primaryStage.show();

                SwingUtilities.invokeLater(new Runnable() {

                     @Override
                     public void run() {
                          JPanel panel = new JPanel();
                          swingNode.setContent(panel);

                          panel.addMouseListener(new MouseListener() {

                               @Override
                               public void mouseReleased(MouseEvent e) {
                                    System.out.println(e);
                               }

                               @Override
                               public void mousePressed(MouseEvent e) {
                                    System.out.println(e);
                               }

                               @Override
                               public void mouseExited(MouseEvent e) {
                                    // System.out.println(e);
                               }

                               @Override
                               public void mouseEntered(MouseEvent e) {
                                    // System.out.println(e);
                               }

                               @Override
                               public void mouseClicked(MouseEvent e) {
                                    System.out.println(e);
                               }
                          });

                          panel.addMouseMotionListener(new MouseMotionListener() {

                               @Override
                               public void mouseMoved(MouseEvent e) {
                                    // System.out.println(e);
                               }

                               @Override
                               public void mouseDragged(MouseEvent e) {
                                    System.out.println(e);
                               }
                          });
                     }
                });
           }
      }


      import java.awt.event.MouseEvent;
      import java.awt.event.MouseListener;
      import java.awt.event.MouseMotionListener;

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

      public class MouseEventSwingTest {

           public MouseEventSwingTest() {
           }

           public static void main(String[] args) {
                SwingUtilities.invokeLater(new Runnable() {

                     @Override
                     public void run() {
                          JFrame frame = new JFrame();
                          frame.setSize(1000, 1000);
                          frame.setVisible(true);

                          JPanel panel = new JPanel();
                          frame.getContentPane().add(panel);

                          panel.addMouseListener(new MouseListener() {

                               @Override
                               public void mouseReleased(MouseEvent e) {
                                    System.out.println(e);
                               }

                               @Override
                               public void mousePressed(MouseEvent e) {
                                    System.out.println(e);
                               }

                               @Override
                               public void mouseExited(MouseEvent e) {
                                    // System.out.println(e);
                               }

                               @Override
                               public void mouseEntered(MouseEvent e) {
                                    // System.out.println(e);
                               }

                               @Override
                               public void mouseClicked(MouseEvent e) {
                                    System.out.println(e);
                               }
                          });

                          panel.addMouseMotionListener(new MouseMotionListener() {

                               @Override
                               public void mouseMoved(MouseEvent e) {
                                    // System.out.println(e);
                               }

                               @Override
                               public void mouseDragged(MouseEvent e) {
                                    System.out.println(e);
                               }
                          });
                     }
                });
           }
      }

        Attachments

          Activity

            People

            • Assignee:
              anthony Anthony Petrov (Inactive)
              Reporter:
              duke J. Duke (Inactive)
            • Votes:
              0 Vote for this issue
              Watchers:
              4 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved:
                Imported: