JDK-8200224 : First mouse press each time JFXPanel gains focus is triggered twice
  • Type: Bug
  • Component: javafx
  • Sub-Component: swing
  • Affected Version: 10,openjfx11
  • Priority: P3
  • Status: Resolved
  • Resolution: Fixed
  • OS: generic
  • CPU: x86_64
  • Submitted: 2018-03-23
  • Updated: 2020-06-11
  • Resolved: 2019-11-27
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
openjfx11.0.8Fixed
Related Reports
Duplicate :  
Relates :  
Relates :  
Description
FULL PRODUCT VERSION :
java version "10" 2018-03-20
Java(TM) SE Runtime Environment 18.3 (build 10+46)
Java HotSpot(TM) 64-Bit Server VM 18.3 (build 10+46, mixed mode)

also

java version "11-ea" 2018-09-18
Java(TM) SE Runtime Environment 18.9 (build 11-ea+5)
Java HotSpot(TM) 64-Bit Server VM 18.9 (build 11-ea+5, mixed mode)

ADDITIONAL OS VERSION INFORMATION :
Microsoft Windows [Version 10.0.16299.192]

A DESCRIPTION OF THE PROBLEM :
The first mouse press each time a JFXPanel gains focus results in the event handler being called twice.  The first call to the handler for mouse clicked reports a click count of two rather than one.  This obviously results in the handling for a double mouse click being performed when the mouse was only clicked once.

Subsequent mouse clicks correcly call the event handler once, until returning to the application after using another window or clicking on a different JFXPanel within the same application, after which the first mouse click is processed twice again.

This does not seem to be an issue with a pure JavaFX structure, but occurs with chunks of new javaFX GUI embedded in older Swing (which can be run in a JApplet where still supported by a browser).

REGRESSION.  Last worked in version 9.0.4

ADDITIONAL REGRESSION INFORMATION: 
java version "9.0.4"
Java(TM) SE Runtime Environment (build 9.0.4+11)
Java HotSpot(TM) 64-Bit Server VM (build 9.0.4+11, mixed mode)

and for many years before that

STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
Use the test code provided.

The first click on one of the coloured labels reports a single click.
Click once on the other label and you see a double click, with further single clicks on the same label a single click.
Click on the first again and the first time is double.
Click on another window, then on one of the lables and the first time is double.

EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
Each single mouse click should result in a single call to the handler.
ACTUAL -
See under steps to reproduce

REPRODUCIBILITY :
This bug can be reproduced always.

---------- BEGIN SOURCE ----------
package jfxpaneltest;

import javafx.application.Platform;
import javafx.embed.swing.JFXPanel;
import javafx.event.EventHandler;
import javafx.scene.Scene;
import javafx.scene.control.Label;
import javafx.scene.layout.StackPane;
import javax.swing.JFrame;
import javax.swing.JPanel;

public class JFXPanelTest {

    public static void main(String[] args) {
        javax.swing.SwingUtilities.invokeLater(new Runnable() {
            public void run() {
                createAndShowGUI();
            }
        });
    }
	
	static void createAndShowGUI() {
        JFrame frame = new JFrame("JFXPanel Test");
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		frame.setSize(300, 300);
		
		JPanel jPanel = new JPanel();
		frame.getContentPane().add(jPanel);
		jPanel.add(new TestPanel("panel 1", "red"));
		jPanel.add(new TestPanel("panel 2", "green"));
		
        frame.setVisible(true);
    }
	
	
	static class TestPanel extends JFXPanel {
		TestPanel(String name, String colour) {
			Platform.runLater(new Runnable() {
				@Override
				public void run() {
					StackPane root = new StackPane();
					root.setStyle("-fx-background-color: " + colour);
					root.getChildren().add(new Label(name));
					Scene scene = new Scene(root);
					setScene(scene);

					root.addEventHandler(javafx.scene.input.MouseEvent.MOUSE_PRESSED,
										   new MousePressedEventHandler());
				}
			});
		}
	}
	
	static class MousePressedEventHandler
						implements EventHandler<javafx.scene.input.MouseEvent> {
		public void handle(javafx.scene.input.MouseEvent e) {
			System.out.println("e.getClickCount() = " + e.getClickCount());
			e.consume();
		}
	}
}
---------- END SOURCE ----------


Comments
Changeset: 1d670f1 Author: Florian Kirmaier Committer: Kevin Rushforth Date: 2019-11-27 16:20:12 +0000 URL: https://git.openjdk.java.net/jfx/commit/1d670f18 8200224: Multiple press event when JFXPanel gains focus
27-11-2019

Removing review-requested label. With the impending move of the jfx repo to GitHub, this will need to be resubmitted as a pull request against https://github.com/openjdk/jfx in order for the review to proceed.
01-10-2019

[~psadhukhan] Please review the PR on GitHub
18-09-2019

Pull request for review: https://github.com/javafxports/openjdk-jfx/pull/591
18-09-2019

THis has been done so by JDK-8087914.
04-04-2018

Issue is reproducible and its a regression in JDK 10+21. Windows 10, 64-bit JDK results ---------------------------------- 8u172 : Pass 9.0.4+11 : Pass 10+21 : Fail <-- regression 10+46: Fail 11-ea+6 : Fail --------------------------------- There are 2 JFXPanel in reproducible test case. After clicking once on any JFXPanel, when we do single-click on another JFXPanel , it gives click count as 2. And then subsequent single clicks on same JFXPanel generates event handler correctly as 1 click count.
26-03-2018