I noticed that JavaFX behaves differently after updated to Ubuntu 18.04. I have a little program to illustrate this issue:
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.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);
}
}
I compiled this program and run on ubuntu 16.04 Oracle java 1.8.0_152, ubuntu 18.04 java 1.8.0_152, ubuntu 18.04 java 1.8.0_192, Windows 10 java 1.8.0_161, and typing 'abcd' (without quotes) into the textfield.
When I run it on ubuntu 16.04 and Windows 10, the output is
KeyPressed:
KeyReleased: a
KeyPressed: a
KeyReleased: ab
KeyPressed: ab
KeyReleased: abc
KeyPressed: abc
KeyReleased: abcd
But when I run the program on ubuntu 18.04, the output is
KeyReleased: a
KeyReleased: ab
KeyReleased: abc
KeyReleased: abcd
Why the difference of same java program on different OS (even with same version of jre)? Which is the correct behavior?