简体   繁体   中英

how to get unicode text from jtextpane java

I have set the jtextpane content type as html and setted the

    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

<![CDATA[<html> <head>

</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; &#2980;&#3018;&#2965;&#3009;&#2980;&#3007; &#2986;&#3006;.&#2990;.&#2965;.&#2997;&#3016; &#2970;&#3015;&#2992;&#3021;&#2984;&#3021;&#2980; &#2965;&#2994;&#3016;&#2991;&#2992;&#2970;&#3009; &#2958;&#2990;&#3021;.&#2958;&#2994;&#3021;.&#2959;. &#2984;&#3015;&#2993;&#3021;&#2993;&#3009; &#2990;&#3009;&#2985;&#3021;&#2980;&#3007;&#2985;&#2990;&#3021; &#2965;&#3006;&#2994;&#3016; &#2990;&#3009;&#2980;&#2994;&#3021;-&#2949;&#2990;&#3016;&#2970;&#3021;&#2970;&#2992;&#3021; &#2972;&#3014;&#2991;&#2994;&#2994;&#3007;&#2980;&#3006;&#2997;&#3016; &#2970;&#2984;&#3021;&#2980;&#3007;&#2980;&#3021;&#2980;&#3009; &#2980;&#2985;&#2980;&#3009; &#2980;&#3018;&#2965;&#3009;&#2980;&#3007; &#2986;&#3007;&#2992;&#2970;&#3021;&#2970;&#3007;&#2985;&#3016;&#2965;&#2995;&#3021; &#2965;&#3009;&#2993;&#3007;&#2980;&#3021;&#2980;&#3009; &#2986;&#3015;&#2970;&#3007;&#2985;&#3006;&#2992;&#3021;. &#2949;&#2980;&#3016;&#2980;&#3021;&#2980;&#3018;&#2975;&#2992;&#3021;&#2984;&#3021;&#2980;&#3009; &#2949;&#2997;&#2992;&#3016; &#2965;&#2975;&#3021;&#2970;&#3007;&#2991;&#3007;&#2994;&#3021; &#2951;&#2992;&#3009;&#2984;&#3021;&#2980;&#3009; &#2984;&#3008;&#2965;&#3021;&#2965;&#3009;&#2997;&#2980;&#3006;&#2965; &#2986;&#3006;.&#2990;.&#2965;. &#2980;&#2994;&#3016;&#2997;&#2992;&#3021; &#2972;&#3007;.&#2965;&#3015;.&#2990;&#2979;&#3007; &#2949;&#2993;&#3007;&#2997;&#3007;&#2980;&#3021;&#2980;&#3006;&#2992;&#3021;.<br> </body> </html> ]]>

I saw this is Tamil Unicode Characters from http://www.utf.ru/tables/tamil.html

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(). So if you donot have Tamil font download it here

First thing you have to do is get a Tamil unicode supported font. 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 :

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



    }

}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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