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

ComboBox produces unexpected event behaviour when ENTER key is pressed

XMLWordPrintable

    • x86_64
    • windows_7

      FULL PRODUCT VERSION :
      java version "1.8.0_74"
      Java(TM) SE Runtime Environment (build 1.8.0_74-b02)
      Java HotSpot(TM) 64-Bit Server VM (build 25.74-b02, mixed mode)


      ADDITIONAL OS VERSION INFORMATION :
      Microsoft Windows [Version 6.1.7601]

      A DESCRIPTION OF THE PROBLEM :
      When a ComboBox has the focus and the ENTER key is pressed,
      the event bubbling doesn't work as expected.

      Expected behaviour is that EventFilters are called from Top to Bottom starting at the scene. After that EventHandlers are called from Bottom to Top.

      Expected sequence:
      - scene filter
      - combobox filter
      - combobox handler
      - scene handler

      When ENTER key is pressed, the event filter and handler on the scene is called a second time.

      observed sequence:
      - scene filter
      - combobox filter
      - scene filter
      - scene handler
      - combobox handler




      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      1. execute the provided example programm
      2. make sure the combobox has the focus.
      3. press ENTER key

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      following lines are printed:

      scene filter
      combobox filter
      combobox handler
      scene handler
      ACTUAL -
      following lines are printed:

      scene filter
      combobox filter
      scene filter
      scene handler
      combobox handler

      REPRODUCIBILITY :
      This bug can be reproduced always.

      ---------- BEGIN SOURCE ----------
      import javafx.application.Application;
      import javafx.scene.Scene;
      import javafx.scene.control.ComboBox;
      import javafx.scene.input.KeyEvent;
      import javafx.scene.layout.VBox;
      import javafx.stage.Stage;

      public class Testpp extends Application {

          public static void main(String... args) {
              launch(args);
          }
          
          @Override
          public void start(Stage primaryStage) throws Exception {
              ComboBox<String> cb = new ComboBox<>();
              cb.getItems().addAll("Test", "hello", "world");

              
              cb.addEventFilter(KeyEvent.KEY_RELEASED, event -> System.out.println("combobox filter"));
              cb.addEventHandler(KeyEvent.KEY_RELEASED, event -> System.out.println("combobox handler"));
              
              VBox root = new VBox(cb);

              Scene scene = new Scene(root);

              scene.addEventFilter(KeyEvent.KEY_RELEASED, event -> System.out.println("scene filter"));
              scene.addEventHandler(KeyEvent.KEY_RELEASED, event -> System.out.println("scene handler"));

              primaryStage.setScene(scene);
              primaryStage.show();
          }
      }
      ---------- END SOURCE ----------

            jgiles Jonathan Giles
            webbuggrp Webbug Group
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated:
              Resolved: