My Java Swing application needs to input Chinese with a Chinese Input Method, like Microsoft Pinyin or Sogou Pinyin, a IME. But we also need to constrain the length user can input.
When we input one Chinese character, there will be few keystrokes to achieve this. In other software, the keystrokes before the final Chinese character seem to be ignored because there is no display for the key letter stroked on these software like these:


But in our Java Swing application, every keystrokes are accepted and displayed on the screen and eventually these letters will be replaced by that Chinese character at the end of the selection or enter stroke. This makes our length checking almost impossible.

Note that our application works fine if there is no IME involved.
My questions are these:
1. is there a way in Java to know a IME is in use or not?
2. is there a way to make Java behave like others to ignore these temporary keystrokes on IME before the final result character?
3. is there any way to check the character length while user is inputing?