JTextPane 显示英文字符和乌尔都语
这是我的乌尔都语文本编辑器的图像。
如您所见,当我尝试显示乌尔都语字符时,英文字符也会显示出来。
我正在为此文本组件实现我自己的键盘侦听器,每当按下按键时,我都会将该键作为字符,将其翻译为相应的乌尔都语,然后使用 document.insertString()
将其插入到 textPane 中code> 方法,但英文字符也会自动显示。
我该怎么做才能使这个英文字符不显示在组件中,而只显示我从英文翻译的乌尔都语字符?
@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
方法。现在还存在另一个问题,就是我的 Enter 键现在不起作用,而其他一些控制键(例如 ctrl)也不起作用。我怎样才能使这些键在我的文档过滤器中工作?
That's the image of my Urdu text editor.
As you can see, when i try to display the Urdu characters, the English characters also show up.
I am implementing my own keyboard listener for this text component and when ever there is a key press, I get that key as a character, translate it to its corresponding Urdu, insert it in textPane using document.insertString()
method, but the English characters are displayed automatically as well.
What can i do so that this English character does not display in the component and it display only the Urdu characters which I translate from English?
@Harrison F :Here is the code you are asking for
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.
EDIT : My problem is solved by implementing a class that extends DocumentFilter
and then overriding its insertString
and replaceString
methods. Now there exists another problem, that is, my enter key is not working now and some other control keys like ctrl. How can i make such keys to work in my document filter?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
s = s+c
锁定可疑对象。已经尝试过
char c = Translate.translateToUrdu(e.getKeyChar());
doc.insertString(carretPos,new String(c),null);
?
s = s+c
locks suspect.Already tried
char c = Translate.translateToUrdu(e.getKeyChar());
doc.insertString(carretPos,new String(c),null);
?