Skip to content

Instantly share code, notes, and snippets.

Created October 23, 2018 09:38
What would you like to do?
* This is a wrapper class that registers the font awesome .ttf included in the package.
* ControlsFX loads this font dynamically at run time from a CDN. Thus, it works only if Internet
* connection is available
* .
* This class registers an included version of the font. The {@link #init()} method should be called
* during the initialization procedure of the application such that the font is available early.
* @author albrecht
private static class FontAwesomeOffline {
private static final String fontLocation = "assets/fonts/fontawesome-webfont.ttf";
private static GlyphFont font;
private FontAwesomeOffline() {
// prevent instances
public static void init() {
InputStream input = FontAwesomeOffline.class.getClassLoader().getResourceAsStream(fontLocation);
if (input != null) {
font = new FontAwesome(input);
GlyphFontRegistry.register(font);"Using {} from local assets.", font.getName());
// Note: if we would close the input stream, icons would not be displayed anymore!
} else {
LOG.error("Could not initialize font awesome: " + fontLocation);
public static GlyphFont getGlyphFont() {
return font;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment