在 JTextArea 中强制 RTL 顺序 [英] Forcing RTL order in a JTextArea

查看:46
本文介绍了在 JTextArea 中强制 RTL 顺序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试强制 JTextArea(以及通过我的应用程序的其他文本组件)允许用户键入 RTL.这适用于阿拉伯语等输入,但我还必须能够将其设置为将其应用于标准文本.因此,如果我输入你好!"它将显示为!olleh".

I am trying to force a JTextArea (and other text components through my application) to allow users to type RTL. This works correctly for input such as Arabic, but I must also be able to set it to apply this to standard text. Therefore, if I type "hello!" it will show up as "!olleh".

我尝试使用 applyOrientation() 方法并将文本区域设置为具有 RTL,如下所示:

I have tried using the applyOrientation() method and setting the text area to have RTL like so:

jTextPane1.getDocument().putProperty(
        TextAttribute.RUN_DIRECTION,
        TextAttribute.RUN_DIRECTION_RTL);

到目前为止我没有成功.有人建议我尝试 Bidi 库,但这些库似乎专注于已经是双向的文本的解释.当我应用上述内容时,我得到了右对齐的文本,但在字符顺序方面它仍然是 LTR.有什么我在这里想念的吗?在查找文本条目应移动克拉的方向时,有没有办法设置 Java 本身检查的值?

I have had no success thus far. It has been suggested that I try the Bidi libraries, but these seem focused on interpretation of text which is already bidirectional. When I apply the above, I get right justified text, but it remains LTR in terms of the character order. Is there anything that I'm missing here? Is there a way to set the value that Java itself checks when looking for which direction text entry should move the carat?

推荐答案

RealSkeptic 指出的 \u202e 和 \u202c 字符解决了我的问题.一种将其后的所有字符强制转换为 RTL 形式,另一种将其后的所有字符强制转换为 LTR 形式.这是一个快速而肮脏的修复,但对于我的问题,它提供了我需要的解决方案.

My problem was solved by the \u202e and the \u202c characters pointed out by RealSkeptic. One will force all characters following it into RTL form, the other forces all characters following it into LTR form. This is a quick and dirty fix, but for my problem, it offered the solution I needed.

这篇关于在 JTextArea 中强制 RTL 顺序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆