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

TextField should not consume function key events

    XMLWordPrintable

Details

    • Bug
    • Resolution: Duplicate
    • P4
    • None
    • 8
    • javafx
    • Windows 8 64bit

    Description

      The typical use case when the developer assigns an event handler for the F1 key to show help in some way.
      However, if the TextField has focus, it will consume all function key events without doing anything.
      If it actually does nothing with function keys, I suggest adding a simple if statement to avoid that.
      The following sample application demonstrates the issue. Try pressing/releasing the F1 key while the TextField has focus; nothing happens.
      Let the button has focus and try pressing/releasing F1 key again. It works!

      import javafx.application.Application;
      import javafx.scene.Scene;
      import javafx.scene.control.Button;
      import javafx.scene.control.Label;
      import javafx.scene.control.TextField;
      import javafx.scene.input.KeyCombination;
      import javafx.scene.layout.VBox;
      import javafx.stage.Stage;

      public class TextFieldConsumesFunctionKeyEvents extends Application{
          @Override
          public void start(Stage primaryStage) throws Exception {
              final TextField textField = new TextField();
              final Label label = new Label();

              primaryStage.setScene(new Scene(new VBox(textField, new Button("Button"), label)));
              primaryStage.getScene().getAccelerators().put(KeyCombination.valueOf("F1"), () -> label.setText("Help!"));
              primaryStage.setTitle("TextField Consumes Function KeyEvents");
              primaryStage.show();
          }

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

      Attachments

        Issue Links

          Activity

            People

              leifs Leif Samuelsson (Inactive)
              asulaimanjfx Anas H. Sulaiman (Inactive)
              Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved:
                Imported: