Class JavaFxFontLoader
-fx-font-family (and ThemeTypography.fontFamily())
without the application having to load each file by hand.
Convention: client applications should place their font files (.ttf/.otf) under
a assets/fonts/ resource directory (e.g.
src/main/resources/assets/fonts/roboto/Roboto-Regular.ttf). Subdirectories are
scanned recursively, so families can be organized into their own folders. Nothing needs
to be registered per file or per family — dropping a font file under that directory is
enough for the application to be able to use its family name.
This runs automatically once at startup (see Bootstrap.dispatch(Class, Stage, String[])), so applications
built on this framework normally never need to call it directly. It's safe to call more
than once (JavaFX simply re-registers the same family) and it's a no-op — not an error —
when the directory doesn't exist, so apps that don't ship custom fonts pay no cost.
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final StringConventional classpath resource directory client apps should place their fonts under. -
Method Summary
Modifier and TypeMethodDescriptionstatic intloadAll()ScansDEFAULT_FONTS_DIRECTORY(on every classpath root — app jar, dependency jars, exploded classes dir when running from an IDE) and registers every font file found withFont.loadFont(InputStream, double).static intSame asloadAll(), but scanning a custom resource directory instead of the conventionalDEFAULT_FONTS_DIRECTORY.
-
Field Details
-
DEFAULT_FONTS_DIRECTORY
Conventional classpath resource directory client apps should place their fonts under.- See Also:
-
-
Method Details
-
loadAll
public static int loadAll()ScansDEFAULT_FONTS_DIRECTORY(on every classpath root — app jar, dependency jars, exploded classes dir when running from an IDE) and registers every font file found withFont.loadFont(InputStream, double).- Returns:
- how many font files were successfully registered
-
loadAll
Same asloadAll(), but scanning a custom resource directory instead of the conventionalDEFAULT_FONTS_DIRECTORY.
-