Reputation: 133
How to add an icon
or a fontawesome icon
to a JFXButton
from the controller class?
public void initialize() {
JFXButton hamburger = new JFXButton();
}
Upvotes: 0
Views: 1192
Reputation: 487
Extending @Mayur Patel answer, use JFXButton constructor with text and graphic, see documentation JFXButton:
public JFXButton(String text, Node graphic) {
super(text, graphic);
initialize();
}
So in your case, it should look like this:
Image image = new Image(getClass().getResourceAsStream("icon.png"));
JFXButton hamburger = new JFXButton("Try me",image);
And with fontawesome icons (remember to import it first in your scene builder, if you are working with scene builder):
<JFXButton fx:id="delete_btn" text="Try me">
<graphic>
<FontAwesomeIconView fill="WHITE" glyphName="play" size="16.0"/>
</graphic>
</JFXButton>
Upvotes: 2
Reputation: 339
Try this, it might work -
JFXButton hamburger = new JFXButton();
Image image = new Image(getClass().getResourceAsStream("icon.png"));
hamburger.setGraphic(new ImageView(image));
Upvotes: 2