如何从控制器类向icon
添加fontawesome icon
或JFXButton
?
public void initialize() {
JFXButton hamburger = new JFXButton();
}
答案 0 :(得分:2)
尝试一下,它可能会起作用-
JFXButton hamburger = new JFXButton();
Image image = new Image(getClass().getResourceAsStream("icon.png"));
hamburger.setGraphic(new ImageView(image));
答案 1 :(得分:1)
扩展@Mayur Patel答案,将JFXButton构造函数与文本和图形一起使用,请参见文档JFXButton:
public JFXButton(String text, Node graphic) {
super(text, graphic);
initialize();
}
因此,在您的情况下,它应如下所示:
Image image = new Image(getClass().getResourceAsStream("icon.png"));
JFXButton hamburger = new JFXButton("Try me",image);
带有带字体的图标(如果您正在使用场景构建器,请记住首先将其导入到场景构建器中)
<JFXButton fx:id="delete_btn" text="Try me">
<graphic>
<FontAwesomeIconView fill="WHITE" glyphName="play" size="16.0"/>
</graphic>
</JFXButton>