I am trying to display font awesome icons on a JButton
. I did the following
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 );
But everything I get is
If I use the font with a JTextArea, it works fine :
JTextArea t = new JTextArea();
t.setRows( 2);
t.setColumns( 12);
t.setFont( font );
t.setText( "\uF0F3 \uF1EC \uf0f3 \uf1ec");
buttonPanel.add(t);
I get