font awesome java,使用AwesomeFont的自定义字体和Java Swing中的unicode字符将图标添加到JButton?...

I have a JButton and I want to add an icon to it. I would like to use the font based icons from FontAwesome which provides a TrueType font file. The icon I am trying to add is the play button icon. The play button icon in the css file for FontAwesome is \f04b which I beleive translates to \uf04b in Java.

This is how I am loading the font in the constructor of by IconButton base class.

public class IconButton extends JButton {

public IconButton() {

try {

InputStream in = this.getClass().getResourceAsStream("/fontawesome-webfont.ttf");

Font ttfBase = Font.createFont(Font.TRUETYPE_FONT, in);

Font ttfReal = ttfBase.deriveFont(Font.BOLD, 24);

setFont(ttfReal);

} catch (FontFormatException e) {

e.printStackTrace();

} catch (IOException e) {

e.printStackTrace();

}

}

}

In the implementing class StartButton this is how I am setting the text.

public class StartButton extends IconButton {

public StartButton() {

setText(String.valueOf('\u0f4b'));

setForeground(Color.BLACK);

}

}

This is what I get. Nothing.

dIZOm.png

Any help is much appreciated.

EDIT: See answer below.

解决方案

I think I solved this actually. The correct character is \uf04b not \u0f4b. Whoops! :)

This is working for me now.

M3sZH.png

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值