Rya*_*ery 13 java fonts swing jbutton font-awesome
我有一个JButton,我想添加一个图标.我想使用FontAwesome中提供TrueType字体文件的基于字体的图标.我想添加的图标是播放按钮图标.FontAwesome的css文件中的播放按钮图标是\f04b
我\uf04b
在Java中所传达的.
这就是我在IconButton基类的构造函数中加载字体的方法.
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();
}
}
}
Run Code Online (Sandbox Code Playgroud)
在实现类StartButton中,这是我设置文本的方式.
public class StartButton extends IconButton {
public StartButton() {
setText(String.valueOf('\u0f4b'));
setForeground(Color.BLACK);
}
}
Run Code Online (Sandbox Code Playgroud)
这就是我得到的.没有.
任何帮助深表感谢.
编辑:见下面的答案.
Rya*_*ery 12
我想我实际上解决了这个问题.正确的角色\uf04b
不是\u0f4b
.哎呦!:)
这对我来说很有用.
归档时间: |
|
查看次数: |
3764 次 |
最近记录: |