Displaying Unicode in a Java JTextArea

I am trying to print unicode in a JTextArea. I have gotten it to print fine to the console but when I try to print it to the textarea, I get boxes for all of the two byte unicode characters. Any help would be much appreciated.

package edu.afit.jieddo; 
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;

public class JTextAreaDemo extends JFrame {
   StringBuffer m = new StringBuffer("u14c7 u14c4 u1557 u00d6");
   StringBuffer m2 =new StringBuffer(" means one.");
   String message = m.append(m2).toString();

   public JTextAreaDemo() {
      super("u14c7 u14c4 u1557 u00d6");
      java.awt.Font font = new java.awt.Font("Arial Unicode MS", java.awt.Font.PLAIN, 18);
      JTextArea textArea = new JTextArea(message);
      textArea.setFont(font);

      java.awt.Container container=this.getContentPane();
      container.add(textArea);
      System.out.println(textArea.getFont().getFamily());// testing output in the command line
   }

   public static void main(String[] args) { 
      JTextAreaDemo frame = new JTextAreaDemo();
      frame.setFont(new Font("Arial Unicode MS",Font.ITALIC,11));
      frame.setDefaultCloseOperation(EXIT_ON_CLOSE);
      frame.pack();
      frame.setVisible(true);
     System.out.println("u14c7 u14c4 u1557 u00d6");
      System.out.println(frame.getFont().getFamily());//testing output in the command line
   }
}

Of those Unicode characters, Arial Unicode MS only provides U+00d6.

Try using DejaVu Sans.

BTW, FileFormat.info is a great resource for Unicode characters. Just replace XXXX in this URL with the unicode number: http://www.fileformat.info/info/unicode/char/XXXX/index.htm . For example: http://www.fileformat.info/info/unicode/char/14C7/index.htm


On my Ubuntu system, which has probably never heard of "Arial Unicode MS", your program executes unchanged, flawlessly. The first two characters I see both in the title bar and the text area, look like snails, pointing in different directions. Or like lowercase d and b lying on their backs.

Apart from a change in size, I see the same characters when I remove the setFont calls.

Thus, it's my educated guess that the fonts you're using don't contain those characters. Err, glyphs for those characters.

There's a font viewer utility in Windows where you can look at all the characters in a font. Do the snails show up?

链接地址: http://www.djcxy.com/p/46890.html

上一篇: 使用Visual Studio的XP上的IIS Developer Express

下一篇: 在Java JTextArea中显示Unicode