SilverCube
SilverCube

Reputation: 574

Getting committed text from Windows IME requires Enter press in JavaFX

I want to provide possibility to enter Chinese characters in JavaFX in Windows. This is my test code for TextArea:

public class Foo extends Application {

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

    @Override
    public void start(Stage primaryStage) throws Exception {
        var textArea = new TextArea();
        textArea.setOnInputMethodTextChanged(e -> {
            System.out.println("Event:" + e.getCommitted().length());
            textArea.appendText(e.getCommitted());
        });
        VBox.setVgrow(textArea, Priority.ALWAYS);
        var root = new VBox(textArea);
        var scene = new Scene(root, 400, 400);
        primaryStage.setScene(scene);
        primaryStage.show();
    }
}

And this is the result:

enter image description here

How it works:

  1. User starts entering characters.
  2. Windows IME appears.
  3. User selects required symbol, for example, by pressing "2".
  4. IME disappears.
  5. Nothing happens until user presses Enter.
  6. Selected symbol is added.

I don't know Chinese but I tried IME with Firefox and it works without #5. Could anyone say how to do it without making user press Enter for every symbol?

Upvotes: 4

Views: 70

Answers (0)

Related Questions