【发布时间】:2014-10-07 10:35:52
【问题描述】:
我正在尝试在 JButton 上显示 font awesome 图标。我做了以下
Font font = null;
try
{
font = Font.createFont(Font.TRUETYPE_FONT, new File("../icons/fontawesome-webfont.ttf"));
font = font.deriveFont(18f);
GraphicsEnvironment ge =
GraphicsEnvironment.getLocalGraphicsEnvironment();
ge.registerFont(font);
}
catch ( FontFormatException ex ){ex.printStackTrace();}
catch ( IOException ex ){ex.printStackTrace();}
private JButton save_btn = new JButton();
save_btn.setFont(font);
save_btn.setText("\uf0c7");
save_btn.setPreferredSize( buttonDimension );
但我得到的都是
如果我使用带有 JTextArea 的字体,它可以正常工作:
JTextArea t = new JTextArea();
t.setRows( 2);
t.setColumns( 12);
t.setFont( font );
t.setText( "\uF0F3 \uF1EC \uf0f3 \uf1ec");
buttonPanel.add(t);
我收到
【问题讨论】:
-
System.out.println(font.canDisplay("\uf0c7"));的输出是什么? -
检查天气系统不支持字体吗?
-
您引用了正确的字符代码吗?这是一个类似的问题:stackoverflow.com/questions/9639894/…
-
ge.registerFont(字体);返回一个布尔值。它的价值是什么?
-
font.canDisplay && registerFont 都返回 true。