如何在Windows XP机器上使用Java Swing显示Unicode字符(例如日语)而不需要安装日语语言包?看起来,将标题文本设置为日语Unicode字符并将字体设置为MS Mincho并不足够。虽然这是在Swing标签中显示Unicode字符所需做的全部工作。
"没有日语语言包"?
看起来您至少需要下载语言字体...
JFrame frame = new JFrame();
String string = "\u30b7\u30f3\u30d7\u30eb\u30c6\u30ad\u30b9\u30c8\u30a8\u30c7\u30a3\u30bf";
JLabel label = new JLabel();
label.setFont(new Font("MS Mincho",Font.PLAIN, 12));
label.setText(string);
frame.getContentPane().add(label);
frame.setFont(new Font("MS Mincho",Font.PLAIN, 12));
frame.setTitle(string);
Java J2SE6(1.6.0)的一般文档在这里,包括字体配置文件
从Java5开始,您不再需要font.properties文件,因为您可以加载字体文件以创建/使用字体。
String fontFileName = "yourfont.ttf";
InputStream is = this.getClass().getResourceAsStream(fontFileName);
Font ttfBase = Font.createFont(Font.TRUETYPE_FONT, is);
Font ttfReal = ttfBase.deriveFont(Font.PLAIN, 24);