在JTextPane中显示urdu字符 [英] Displaying urdu characters in JTextPane

查看:169
本文介绍了在JTextPane中显示urdu字符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在



项目以纯UTF-8编码

  import javax.swing。*; 
import java.awt。*;

公共类示例{

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(和平对你(你好) - السلامعلیکم+\ n);
textA.append(和平在你身边(你好) - وعلیکمالسلام+\ n);
textA.append(我很高兴见到你 - آپسےکرخوشیہوئی+\ n);
textA.append(你会说英语吗? - کیاآپانگریزیبولتےےیں?+\ n);

frameA.add(textA);
frameA.pack();
frameA.setVisible(true);
}

public static void main(String [] args){
SwingUtilities.invokeLater(new Runnable(){

@Override
public void run(){
示例考试=新示例();
}
});
}
}

编辑:



谢谢Stas



我把它放到了JTextArea



添加了JTextPane示例

  import javax.swing。*; 
import java.awt。*;

公共类示例{

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(和平在你身边(你好) - السلامعلیکم+\ n
+和平也在你身边(你好) - وعلیکمالسلام+\ n
+我很高兴认识你 - آپسےکرخوشیہوئی+\ n
+你会说英语吗? - کیاآپانگریزیبولتےےیں?+\ N);

frameA.add(textP);
frameA.pack();
frameA.setVisible(true);
}

public static void main(String [] args){
SwingUtilities.invokeLater(new Runnable(){

@Override
public void run(){
示例考试=新示例();
}
});
}
}


How can I display a single Urdu character in a JTextPane? I have translated English characters to Urdu characters. But I can't find any way to correctly display those characters into my text component.

My goal is to:

  1. Get the key pressed on the keyboard.
  2. Convert that key into the equivalent Urdu character.
  3. Display it in my text component (JTextPane).

I've completed step 1 and 2 but can't work out the last one.

解决方案

to 3- display it in my text component that is JTextPane

source Wikipedia

project Encoded in plain 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();
            }
        });
    }
} 

EDIT:

thanks Stas

by mistake I put that to the JTextArea

added JTextPane example

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

这篇关于在JTextPane中显示urdu字符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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