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

First mouse press each time JFXPanel gains focus is triggered twice

    XMLWordPrintable

    Details

    • Subcomponent:
    • Introduced In Build:
      b21
    • Introduced In Version:
      10
    • CPU:
      x86_64
    • OS:
      generic

      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 ----------

        Attachments

          Activity

            People

            • Assignee:
              psadhukhan Prasanta Sadhukhan
              Reporter:
              webbuggrp Webbug Group
            • Votes:
              0 Vote for this issue
              Watchers:
              4 Start watching this issue

              Dates

              • Created:
                Updated: