Add font awesome to menu item javafx

LinkedIn Tweet Facebook
Add font awesome to menu item javafx

Maven dependency to add font awesome to your project

<dependency>
    <groupId>de.jensd</groupId>
    <artifactId>fontawesomefx</artifactId>
    <version>8.9</version>
</dependency>

We will require the GlyphsDude class for setting the icon. Since FontAwesomeIcon object cannot be directly used in MenuItem constructor.

import de.jensd.fx.glyphs.GlyphsDude;
import de.jensd.fx.glyphs.fontawesome.FontAwesomeIcon;
import javafx.scene.control.ContextMenu;
import javafx.scene.control.MenuItem;

MenuItem downloadMenuItem;
downloadMenuItem = new MenuItem("Download");
GlyphsDude.setIcon(downloadMenuItem, FontAwesomeIcon.DOWNLOAD);
ContextMenu menu = new ContextMenu();
menu.getItems().add(downloadMenuItem);