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

When unfocused, the JFXPanel recognizes a double click instead of a single click

    XMLWordPrintable

Details

    • x86_64
    • windows_10

    Description

      ADDITIONAL SYSTEM INFORMATION :
      JDK 11 / OpenJFX 11

      A DESCRIPTION OF THE PROBLEM :
      Following scenario:
      * multiple JFXPanels
      * single click on the one that does not have the focus
      -> double click is recognized

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      Following scenario:
      * multiple JFXPanels
      * single click on the one that does not have the focus

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      ClickCount should be 1
      ACTUAL -
      ClickCount is 2

      ---------- BEGIN SOURCE ----------
      package test;

      import java.awt.Color;
      import java.awt.FlowLayout;

      import javax.swing.JFrame;
      import javax.swing.JOptionPane;
      import javax.swing.JPanel;
      import javax.swing.SwingUtilities;
      import javax.swing.border.LineBorder;

      import javafx.application.Platform;
      import javafx.embed.swing.JFXPanel;
      import javafx.scene.Scene;
      import javafx.scene.control.Label;
      import javafx.scene.input.MouseEvent;

      public class FxPanelDoubleClick
      {

         public static void main(String... args)
         {
            JFrame frame = new JFrame("JFXPanel Double Click Panel");
            JOptionPane.setRootFrame(frame);
            frame.setSize(300, 100);
            frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

            JFXPanel jfxPanel1 = new JFXPanel();
            jfxPanel1.setSize(100, 30);
            jfxPanel1.setBorder(new LineBorder(Color.BLACK));
            Label label1 = new Label("AAA");
            label1.setPrefWidth(100);

            JFXPanel jfxPanel2 = new JFXPanel();
            jfxPanel2.setSize(100, 30);
            jfxPanel2.setBorder(new LineBorder(Color.BLACK));
            Label label2 = new Label("BBB");
            label2.setPrefWidth(100);

            JPanel jPanel = new JPanel(new FlowLayout());
            jPanel.add(jfxPanel1);
            jPanel.add(jfxPanel2);
            frame.setContentPane(jPanel);

            frame.setVisible(true);
            Platform.runLater(() -> {
               jfxPanel1.setScene(new Scene(label1));
               label1.addEventHandler(MouseEvent.MOUSE_CLICKED,
                                      mE -> SwingUtilities.invokeLater(() -> JOptionPane.showMessageDialog(jfxPanel1, "AAA clicked " + mE.getClickCount() + " times"))
                                     );
               jfxPanel2.setScene(new Scene(label2));
               label2.addEventHandler(MouseEvent.MOUSE_CLICKED,
                                      mE -> SwingUtilities.invokeLater(() -> JOptionPane.showMessageDialog(jfxPanel1, "BBB clicked " + mE.getClickCount() + " times"))
                                     );
            });

         }
      }

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

      CUSTOMER SUBMITTED WORKAROUND :
      Current implementation of processMouseEvent(MouseEvent) in the JFXPanel works:

      @Override
         protected void processMouseEvent(MouseEvent e)
         {
            if ((e.getID() == MouseEvent.MOUSE_PRESSED) &&
                (e.getButton() == MouseEvent.BUTTON1) && isFocusable() &&
                !hasFocus())
            {
               requestFocus();
               SwingUtilities.invokeLater(new LambdaRunner(() -> sendMouseEventToFX(e)));
            }
            else
            {
               sendMouseEventToFX(e);
               super.processMouseEvent(e);
            }
         }

      Attachments

        Issue Links

          Activity

            People

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

              Dates

                Created:
                Updated:
                Resolved: