【发布时间】:2014-12-02 13:36:46
【问题描述】:
我在我的 Swing 应用程序中使用自定义字体并像这样加载它:
URL l = ClassLoader.class.getResource("/resource/template/CarroisGothic-Regular.ttf");
Font font = Font.createFont(Font.TRUETYPE_FONT, l.openStream());
font = font.deriveFont(Font.PLAIN, 13);
GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
ge.registerFont(font);
UIManager.put("ComboBox.font", font);
它在区域设置/语言设置为英语的系统上运行良好,但对于其他语言(例如俄语),它会显示乱码。
这就是我显示月份名称的方式:
String[] months = new DateFormatSymbols().getMonths();
for (int i = 0; i < months.length && i < 12; i++) {
cmbMonth.addItem(months[i]);
if(i == Calendar.getInstance().get(Calendar.MONTH) + 1) {
cmbMonth.setSelectedIndex(i);
}
}
【问题讨论】:
-
听起来那个字体不包含西里尔符号。正方形而不是正确的符号通常表示缺少字形。我认为它适用于系统字体。
-
可能也需要this。