JTextPane 显示英文字符和乌尔都语

发布于 2024-12-19 01:06:51 字数 936 浏览 0 评论 0原文

在此处输入图像描述

这是我的乌尔都语文本编辑器的图像。

如您所见,当我尝试显示乌尔都语字符时,英文字符也会显示出来。

我正在为此文本组件实现我自己的键盘侦听器,每当按下按键时,我都会将该键作为字符,将其翻译为相应的乌尔都语,然后使用 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)也不起作用。我怎样才能使这些键在我的文档过滤器中工作?

enter image description here

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

ㄟ。诗瑗 2024-12-26 01:06:51

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);

?

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文