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

ComboBox: cancel button must not be triggered if escape is consumed by combo handler


    • Type: Bug
    • Status: In Progress
    • Priority: P3
    • Resolution: Unresolved
    • Affects Version/s: openjfx11
    • Fix Version/s: tbd
    • Component/s: javafx
    • Subcomponent:
    • Understanding:
      Fix Understood


      To reproduce, run the example below, focus one of the combo, press escape

      expected: message from combo handler printed
      actual: message from cancel button is printed before message from combo handler

      The bug is similar to JDK-8207759 (there reported against ENTER and TextField), with the same underlying reason: ComboBoxBaseBehavior has a keyMapping for ESCAPE which forwards the event to the combo's parent if interpreted as not used. This manual firing of the received keyEvent wrecks the event deliverance sequence such that handlers in the parent hierarchy see the event before the consuming singleton handler of the combo.

      The fix is basically the same: in ComboBoxBaseBehavior, replace the manual forwarding by letting the event travel "naturally" up the chain.

      The example:

      public class ComboCancelButton extends Application {

          private Parent createContent() {
              ObservableList<String> data= FXCollections.observableArrayList("one", "two");
              ComboBox<String> editable = new ComboBox<>(data);
              EventHandler<KeyEvent> consumer = e -> {
                  if (e.getCode() == ESCAPE) {
                      System.out.println("consuming escape");
              ComboBox<String> notEditable = new ComboBox<>(data);
              Button cancel = new Button("Cancel");
              cancel.setOnAction(a -> System.out.println("cancel triggered"));
              VBox content= new VBox(10, editable, notEditable, cancel);
              return content;

          public void start(Stage stage) throws Exception {
              stage.setScene(new Scene(createContent()));

          public static void main(String[] args) {



          Issue Links



              • Assignee:
                fastegal Jeanette Winzenburg
                fastegal Jeanette Winzenburg
              • Votes:
                0 Vote for this issue
                1 Start watching this issue


                • Created: