简体   繁体   English

如何从jtextpane java获取unicode文本

[英]how to get unicode text from jtextpane java

I have set the jtextpane content type as html and setted the 我已经将jtextpane内容类型设置为html并设置了

    ta_description = new JTextPane();
    ta_description.setContentType("text/html");
    ta_description.setFont(new Font("Latha", Font.PLAIN, 12));
    ta_description.setText("<![CDATA[<br>வேலூர் மாவட்டம், அணைக்கட்டு 
        தொகுதி பா.ம.க.வை சேர்ந்த கலையரசு எம்.எல்.ஏ. நேற்று முன்தினம் 
        காலை முதல்-அமைச்சர் ஜெயலலிதாவை சந்தித்து தனது தொகுதி 
        பிரச்சினைகள் குறித்து பேசினார். அதைத்தொடர்ந்து அவரை கட்சியில் 
        இருந்து நீக்குவதாக பா.ம.க. தலைவர் ஜி.கே.மணி அறிவித்தார்.<br>]]>);

When i get this text using ta_description.gettext() and it will be like as below 当我使用ta_description.gettext()获得此文本时,它将如下所示

<![CDATA[<html> <head> <![CDATA [<html> <head>

</head> <body> <br> &#2997;&#3015;&#2994;&#3010;&#2992;&#3021; </ head> <body> <br>&#2997;&#3015;&#2994;&#3010;&#2992;&#3021; &#2990;&#3006;&#2997;&#2975;&#3021;&#2975;&#2990;&#3021;, &#2949;&#2979;&#3016;&#2965;&#3021;&#2965;&#2975;&#3021;&#2975;&#3009; &#2990;&#3006;&#2997;&#2975;&#3021;&#2975;&#2990;&#3021 ;,&#2949;&#2979;&#3016;&#2965;& #3021;&#2965;&#2975;&#3021;&#2975;&#3009; &#2980;&#3018;&#2965;&#3009;&#2980;&#3007; &#2980;&#3018;&#2965;&#3009;&#2980;&#3007; &#2986;&#3006;.&#2990;.&#2965;.&#2997;&#3016; &#2986;&#3006;。&#2990;。&#2965;。&#2997;&#3016; &#2970;&#3015;&#2992;&#3021;&#2984;&#3021;&#2980; &#2970;&#3015;&#2992;&#3021;&#2984;&#3021;&#2980; &#2965;&#2994;&#3016;&#2991;&#2992;&#2970;&#3009; &#2965;&#2994;&#3016;&#2991;&#2992;&#2970;&#3009; &#2958;&#2990;&#3021;.&#2958;&#2994;&#3021;.&#2959;. &#2958;&#2990;&#3021;。&#2958;&#2994;&#3021;。&#2959 ;. &#2984;&#3015;&#2993;&#3021;&#2993;&#3009; &#2984;&#3015;&#2993;&#3019;&#2993;&#3009; &#2990;&#3009;&#2985;&#3021;&#2980;&#3007;&#2985;&#2990;&#3021; &#2990;&#3009;&#2985;&#3021;&#2980;&#3007;&#2985;&#2990;&#3021; &#2965;&#3006;&#2994;&#3016; &#2965;&#3006;&#2994;&#3016; &#2990;&#3009;&#2980;&#2994;&#3021;-&#2949;&#2990;&#3016;&#2970;&#3021;&#2970;&#2992;&#3021; &#2990;&#3009;&#2980;&#2994;&#3021;-&#2949;&#2990;&#3016;&#2970;&#3021;&#2970;&#2992;& #3021; &#2972;&#3014;&#2991;&#2994;&#2994;&#3007;&#2980;&#3006;&#2997;&#3016; &#2972;&#3014;&#2991;&#2994;&#3007;&#2980;&#3006;&#2997;&#3016; &#2970;&#2984;&#3021;&#2980;&#3007;&#2980;&#3021;&#2980;&#3009; &#2970;&#2984;&#3021;&#2980;&#3007;&#2980;&#3021;&#2980;&#3009; &#2980;&#2985;&#2980;&#3009; &#2980;&#2985;&#2980;&#3009; &#2980;&#3018;&#2965;&#3009;&#2980;&#3007; &#2980;&#3018;&#2965;&#3009;&#2980;&#3007; &#2986;&#3007;&#2992;&#2970;&#3021;&#2970;&#3007;&#2985;&#3016;&#2965;&#2995;&#3021; &#2986;&#3007;&#2992;&#2970;&#3021;&#2970;&#3007;&#2985;&#3016;&#2965;&#2995;&#3021; &#2965;&#3009;&#2993;&#3007;&#2980;&#3021;&#2980;&#3009; &#2965;&#3009;&#2993;&#3007;&#2980;&#3021;&#2980;&#3009; &#2986;&#3015;&#2970;&#3007;&#2985;&#3006;&#2992;&#3021;. &#2986;&#3015;&#2970;&#3007;&#2985;&#3006;&#2992;&#3021;。 &#2949;&#2980;&#3016;&#2980;&#3021;&#2980;&#3018;&#2975;&#2992;&#3021;&#2984;&#3021;&#2980;&#3009; &#2949;&#2980;&#3016;&#2980;&#3021;&#2980;&#3018;&#2975;&#2992;&#3021;&#2984;&#3021;&# 2980;&#3009; &#2949;&#2997;&#2992;&#3016; &#2949;&#2997;&#2992;&#3016; &#2965;&#2975;&#3021;&#2970;&#3007;&#2991;&#3007;&#2994;&#3021; &#2965;&#2975;&#3021;&#2970;&#3007;&#2991;&#3007;&#2994;&#3021; &#2951;&#2992;&#3009;&#2984;&#3021;&#2980;&#3009; &#2951;&#2992;&#3009;&#2984;&#3021;&#2980;&#3009; &#2984;&#3008;&#2965;&#3021;&#2965;&#3009;&#2997;&#2980;&#3006;&#2965; &#2984;&#3008;&#2965;&#3021;&#2965;&#3009;&#2997;&#2980;&#3006;&#2965; &#2986;&#3006;.&#2990;.&#2965;. &#2986;&#3006;。&#2990;。&#2965;。 &#2980;&#2994;&#3016;&#2997;&#2992;&#3021; &#2980;&#2994;&#3016;&#2997;&#2992;&#3021; &#2972;&#3007;.&#2965;&#3015;.&#2990;&#2979;&#3007; &#2972;&#3007;。&#2965;&#3015;。&#2990;&#2979;&#3007; &#2949;&#2993;&#3007;&#2997;&#3007;&#2980;&#3021;&#2980;&#3006;&#2992;&#3021;.<br> </body> </html> ]]> &#2949;&#2993;&#3007;&#2997;&#3007;&#2980;&#3021;&#2980;&#3006;&#2992;&#3021 ;. <br> </正文> </ html>]]>

I saw this is Tamil Unicode Characters from http://www.utf.ru/tables/tamil.html 我从http://www.utf.ru/tables/tamil.html看到这是泰米尔语Unicode字符

I need to get text correctly and i dono how to get text properly. 我需要正确获取文本,我也不知道如何正确获取文本。

Java uses font from the system , so if the system doesn't contain a specific font then you can deploy that font within your application using Font.createFont(). Java使用系统中的字体,因此,如果系统不包含特定字体,则可以使用Font.createFont()在应用程序中部署该字体。 So if you donot have Tamil font download it here 因此,如果您没有泰米尔语字体,请在此处下载

First thing you have to do is get a Tamil unicode supported font. 您要做的第一件事就是获取Tamil unicode支持的字体。 Somthing like this: 像这样的东西:

Font tamil =new Font("Latha", Font.BOLD,15);//I had a font Latha which supports tamil font

Then set the font of your JTextPane : 然后设置JTextPane的字体:

ta_description.setFont(tamil);

看看它在我的系统中的外观

Full Code: 完整代码:

import java.awt.BorderLayout;
import java.awt.EventQueue;
import java.awt.Font;

import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JTextPane;
import javax.swing.border.EmptyBorder;

public class Test extends JFrame {

    private JPanel contentPane;

    /**
     * Launch the application.
     */
    public static void main(String[] args) {
        EventQueue.invokeLater(new Runnable() {
            public void run() {
                try {
                    Test frame = new Test();
                    frame.setVisible(true);
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
        });
    }

    /**
     * Create the frame.
     */
    public Test() {
        setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        setBounds(100, 100, 450, 300);
        contentPane = new JPanel();
        contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
        contentPane.setLayout(new BorderLayout(0, 0));
        setContentPane(contentPane);

        JTextPane textPane = new JTextPane();
        contentPane.add(textPane, BorderLayout.CENTER);
        Font TamilFont=new Font("Latha", Font.BOLD,15);
        textPane.setFont(TamilFont);



    }

}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM