Associate a keyboard input with a TextField in Jav

2019-06-11 07:28发布

问题:

I am trying to have two JavaFX TextFields, one which takes input using a standard English keyboard/language, and the other using a Japanese keyboard/language.

This answer addresses the problem for Swing, but the JavaFX TextField doesn't have the needed getInputContext() method.

My plan was to either catch a focus event and change the Locale to Japanese, or associate a specific Locale with the Japanese TextField. However, I don't know how to actually achieve either of these.

I have a suspicion the Java Input Method Client API may be needed.

I am using Windows 8, but it would be nice to have a OS independent answer.

回答1:

The only thing that comes close that i could find was:

textfield.getText().regionMatches();

however im not sure that this is the one your looking for.

Update

i also found

txt_message.getText().format(Locale.JAPANESE, format, args)