JDK-8094695 : TextField should not consume function key events
  • Type: Bug
  • Component: javafx
  • Sub-Component: controls
  • Affected Version: 8
  • Priority: P4
  • Status: Resolved
  • Resolution: Duplicate
  • Submitted: 2014-03-17
  • Updated: 2015-06-12
  • Resolved: 2014-03-17
Related Reports
Duplicate :  
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();
    }
}
Comments
Duplicate of RT-24122.
17-03-2014