Font Awesome Icons in JavaFX (Part 2/3)

To use the font in a programmatically created GUI, you just have to set it on the desired element:

static final ICON_ANDROID = "\uf17b";
Label label = new Label(ICON_ANDROID); 
label.setFont(fontAwesome);

The only inconvenience is, that we have to keep the reference to the font across the application. A simple way to fix it, is to set the style information about the font with setStyle

label.setStyle("-fx-font-family: 'FontAwesome'");

Or to set the font family in css:

.fa-label {
  -fx-font-family: 'FontAwesome';
}

In this example, the created .fa-label css class can be used to apply the font on selected elements.