這是我的烏爾都語文本編輯器的圖像。
正如您所看到的,當我嘗試顯示烏爾都語字符時,英語字符也顯示出來。
我正在爲這個文本組件實現我自己的鍵盤監聽器,並且當有按鍵時,我將該鍵作爲字符獲取,將其翻譯爲相應的烏爾都語,使用document.insertString()
方法將其插入到textPane中,但英語字符也會自動顯示。
我該怎麼做才能讓這個英文字符不會顯示在組件中,它只顯示我從英文翻譯的烏爾都語字符?
@Harrison F:這是你所要求的
char b = e.getKeyChar();// e is the object of class KeyEvent
char c = Translate.translateToUrdu(b);// its my own class for translation
s = s+c;// converting the character to string.
doc.insertString(carretPos,s,null); // inserting into the document
s = ""; //setting the string object to "" so that next time i can use it again.
編輯代碼:我的問題是通過實施延伸DocumentFilter
,然後覆蓋其insertString
和replaceString
方法的類來解決。現在還有另外一個問題,就是我的回車鍵現在不能工作,還有一些其他的控制鍵像ctrl。我怎樣才能使這些鍵在我的文檔過濾器中工作?
你可以顯示你的'document.insertString()'的代碼嗎?我懷疑你並沒有剝離出原來的角色,因此它會隨着烏爾都語角色一起被追加。看到代碼將有極大的幫助。 –