JDK-8222208 : When unfocused, the JFXPanel recognizes a double click instead of a single click
  • Type: Bug
  • Component: javafx
  • Sub-Component: swing
  • Affected Version: openjfx11
  • Priority: P4
  • Status: Closed
  • Resolution: Duplicate
  • OS: windows_10
  • CPU: x86_64
  • Submitted: 2019-03-19
  • Updated: 2020-04-02
  • Resolved: 2020-04-02
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
Other
tbdResolved
Related Reports
Duplicate :  
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);
      }
   }