我正在尝试在 JTextArea 中打印 unicode。我已经让它可以很好地打印到控制台,但是当我尝试将它打印到文本区域时,我得到了所有两个字节 unicode 字符的框。任何帮助将不胜感激。
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
}
}
最佳答案
在这些 Unicode 字符中,Arial Unicode MS 仅提供 U+00d6。
尝试使用 DejaVu Sans .
顺便说一句,FileFormat.info是 Unicode 字符的重要资源。只需将此 URL 中的 XXXX 替换为 unicode 编号: http://www.fileformat.info/info/unicode/char/XXXX/index.htm .例如:http://www.fileformat.info/info/unicode/char/14C7/index.htm
关于java - 在 Java JTextArea 中显示 Unicode,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3266001/