0
我正在用java編寫英文/阿拉伯語字典。我希望應用根據搜索語言自動將鍵盤設置爲合適的佈局。我保存的鍵盤區域設置信息是這樣的:使用InputContext.selectInputMethod指定鍵盤佈局總是失敗
JTextField tf = (JTextField) e.getSource();
InputContext ic = tf.getInputContext();
Pref.setInputLocale (Pref.getSearchIndex(), ic.getLocale().toString());
而且這樣的方式進行恢復:
JTextField tf = Ui.makeTextField (20, "", searchListener);
controlPanel.add(tf);
String ls = Pref.getInputLocale(Pref.getSearchIndex());
if (ls.length() > 0) {
Locale l = new Locale (ls);
InputContext ic = tf.getInputContext();
System.out.println (ic.toString());
System.out.println (l.toString());
System.out.println (ic.selectInputMethod (l));
}
系統輸出輸入語言的三個連續交換機看起來是這樣的:
[email protected]
en_us
false
[email protected]
ar_eg
false
[email protected]
en_us
false
系統輸出顯示語言環境字符串正在保存併成功恢復,但InputContext.selectInputMethod始終返回false,並且鍵盤不轉換編輯阿拉伯文。有什麼建議麼?