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

TextField.setOnKeyPressed not working on Ubuntu 18.04

XMLWordPrintable

      ADDITIONAL SYSTEM INFORMATION :
      Linux asus14 4.15.0-43-generic #46-Ubuntu SMP Thu Dec 6 14:45:28 UTC 2018 x86_64 x86_64 x86_64 GNU/Linux


      A DESCRIPTION OF THE PROBLEM :
      TextField.setOnKeyPressed is not working on Ubuntu 18.04. It works on Ubuntu 16.04 and Windows 10.

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      compile and run the following program on Ubuntu 18.04, type in string "abcd" (without quotes) to the TextField.


      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      The expected output is
      KeyPressed:
      KeyReleased: a
      KeyPressed: a
      KeyReleased: ab
      KeyPressed: ab
      KeyReleased: abc
      KeyPressed: abc
      KeyReleased: abcd

      ACTUAL -
      the console print out is:
      KeyReleased: a
      KeyReleased: ab
      KeyReleased: abc
      KeyReleased: abcd



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

      import javafx.application.Application;
      import javafx.scene.Group;
      import javafx.scene.Scene;
      import javafx.scene.control.TextField;
      import javafx.stage.Stage;

      public class Main extends Application {

          @Override
          public void start(Stage primaryStage) throws Exception{
              primaryStage.setTitle("Key Pressed");
              Group root = new Group();
              Scene scene = new Scene(root, 300, 275);
              TextField textField = new TextField();
              //textField.setOnKeyTyped(e -> System.out.println("KeyTyped: " + textField.getText()));
              textField.setOnKeyPressed(e -> System.out.println("KeyPressed: " + textField.getText()));
              textField.setOnKeyReleased(e -> System.out.println("KeyReleased: " + textField.getText()));
              root.getChildren().add(textField);
              primaryStage.setScene(scene);
              primaryStage.show();
          }


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

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

      FREQUENCY : always


            pbansal Pankaj Bansal (Inactive)
            webbuggrp Webbug Group
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

              Created:
              Updated:
              Resolved: