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

ListView consumes Escape (CancelEdit) even when not editing

    Details

    • Subcomponent:
    • CPU:
      x86_64
    • OS:
      linux

      Description

      FULL PRODUCT VERSION :
      openjdk version "1.8.0_121"
      OpenJDK Runtime Environment (build 1.8.0_121-8u121-b13-2-b13)
      OpenJDK 64-Bit Server VM (build 25.121-b13, mixed mode)

      ADDITIONAL OS VERSION INFORMATION :
      Linux 4.9.0-1-amd64 #1 SMP Debian 4.9.2-2 (2017-01-12) x86_64 GNU/Linux

      A DESCRIPTION OF THE PROBLEM :
      ListView consumes key pressed events for KeyCode.ESCAPE even when not currently editing, which makes it impossible to e.g. close popups on escape if a ListView is focused.
      It stands to reason that a ListView should check it's editing state before consuming Escape as a CancelEdit.
      This may apply to other controls and other event types, as the root cause seems to be in the implementation of BehaviorBase.

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      Add a KeyPressed event handler to a parent containing a ListView and some other controls. Press Escape when the ListView has focus, but isn't currently editing.

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      The Event is expected to bubble up to the parent, as is the case with many other controls.
      ACTUAL -
      The ListView consumes the event, even though it isn't technically cancelling the edit, as it's not currently editing.

      REPRODUCIBILITY :
      This bug can be reproduced always.

      ---------- BEGIN SOURCE ----------
      package sample;

      import javafx.application.Application;
      import javafx.scene.Scene;
      import javafx.scene.control.ComboBox;
      import javafx.scene.control.ListView;
      import javafx.scene.control.TextField;
      import javafx.scene.input.KeyEvent;
      import javafx.scene.layout.VBox;
      import javafx.stage.Stage;


      public class Demo extends Application {
          @Override
          public void start(Stage stage) throws Exception {
              VBox vb = new VBox(5.0, new TextField(), new ComboBox<String>(), new ListView<>());
              // Note: This handler won't be called as long as the ListView has focus, even though it will never be in editing state.
              vb.addEventHandler(KeyEvent.KEY_PRESSED, keyEvent -> System.err.println("Key pressed: " + keyEvent.getCode()));
              stage.setScene(new Scene(vb));
              stage.show();
          }


          public static void main(String[] args) throws Exception {
              launch(args);
          }
      }

      ---------- END SOURCE ----------

      CUSTOMER SUBMITTED WORKAROUND :
      This can be circumvented in cases where an EventFilter is applicable, but there are cases an EventFilter can't be used due to bubbling order (other controls in parent need to take precedence, etc).

        Attachments

          Activity

            People

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

              Dates

              • Created:
                Updated: