如何显示单个 Urdu JTextPane
中的字符?我已将英文字符翻译成乌尔都语字符。但是我找不到任何方法将这些字符正确显示到我的文本组件中。
我的目标是:
- 获取键盘上按下的键。
- 将该键转换为等效的乌尔都语字符。
- 在我的文本组件 (
JTextPane
) 中显示它。
我已经完成了第 1 步和第 2 步,但无法计算出最后一个。
最佳答案
到 3- 在我的文本组件 JTextPane 中显示它
项目以纯 UTF-8 编码
import javax.swing.*;
import java.awt.*;
public class Example {
private JFrame frameA = new JFrame("Example");
private JTextArea textA = new JTextArea(10, 5);
public Example() {
frameA.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
textA.setForeground(new Color(255, 150, 150));
textA.setText("Peace be upon you (Hello) - السلام علیکم " + "\n");
textA.append("Peace be upon you too (Hello) - و علیکم السلام " + "\n");
textA.append("I am happy to meet you - آپ سے مل کر خوشی ہوئی" + "\n");
textA.append("Do you speak English? - کیا آپ انگریزی بولتے ہیں؟" + "\n");
frameA.add(textA);
frameA.pack();
frameA.setVisible(true);
}
public static void main(String[] args) {
SwingUtilities.invokeLater(new Runnable() {
@Override
public void run() {
Example exam = new Example();
}
});
}
}
编辑:
谢谢你
我错误地把它放到了 JTextArea
添加了 JTextPane 示例
import javax.swing.*;
import java.awt.*;
public class Example {
private JFrame frameA = new JFrame("Example");
private JTextPane textP = new JTextPane();
public Example() {
frameA.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
textP.setForeground(new Color(255, 150, 150));
textP.setText("Peace be upon you (Hello) - السلام علیکم " + "\n"
+"Peace be upon you too (Hello) - و علیکم السلام " + "\n"
+"I am happy to meet you - آپ سے مل کر خوشی ہوئی" + "\n"
+"Do you speak English? - کیا آپ انگریزی بولتے ہیں؟" + "\n");
frameA.add(textP);
frameA.pack();
frameA.setVisible(true);
}
public static void main(String[] args) {
SwingUtilities.invokeLater(new Runnable() {
@Override
public void run() {
Example exam = new Example();
}
});
}
}
关于java - 在 JTextPane 中显示乌尔都语字符,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8316923/