Sameera Kumarasingha
Sameera Kumarasingha

Reputation: 2988

Display unicode characters in Java

I tried to display some unicode characters in the range Sinhala (80: 0D80–0DFF) in java swing components. Those letters are displayed correctly in eclipse console, but those are shown as boxs in JButtons , JTextArea, JTextPane & etc.

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

public class Unicode extends JFrame{

    public Unicode(){

        super("ක් කැ කැ කු අ ඉ");

        add(new JButton("ක් කැ කැ කු අ ඉ \u0D88"),BorderLayout.NORTH);
        add(new JTextField("ක් කැ කැ කු අ ඉ"), BorderLayout.CENTER);

        setSize(500,500);
        setVisible(true);
    }

    public static void main(String a[]){
        new Unicode();
    }
 }

I tried to display by using characters and character codes, but neither works. Many answers given by the google doesn't work. Please give me a help. I'm using windows 7 with java 1.6.

Thank you...

Upvotes: 3

Views: 5638

Answers (2)

Tharindu Shehan
Tharindu Shehan

Reputation: 96

Please set Font that "IskolaPotha". I think it work properly.(I used this font). but Swing componetns(without JFrame) dose not display "ක්‍යෝ"unicode chars properly.

Upvotes: 2

Ritesh
Ritesh

Reputation: 1847

If eclipse is able to render sinhala fonts, then it is for sure that you have fontfile that has sinhala glyphs. Now swing component is not able to pick that font up so you need to explicitly enforce to pick that file to display.

So as to make generalize solution, you need to iterate over code pages and have to find which supports sinhala range of unicodes.

Please have look at this link for more info:

http://content.hccfl.edu/pollock/Java/Fonts.htm

Upvotes: 1

Related Questions