I made use of the FA badges by adapting the Jens Deters approach .
Its routines target the dynamic composition of gui, which is the opposite of the declarative path fxml. However, its AwesomeIcon enum (which displays FA friendly names with Unicode characters) is perfect for my purposes.
It should start with static font loading in the main / app class:
public class App extends Application { static { Font.loadFont(App.class.getResource("/font/fontawesome-webfont.ttf").toExternalForm(), 10); } @Override public void start(final Stage primaryStage) throws Exception { URL resource = getClass().getResource("/fxml/app.fxml"); primaryStage.setScene(new Scene((Parent) FXMLLoader.load(resource), 500, 500)); primaryStage.setTitle("FontAwesomeFX demo"); primaryStage.show(); } public static void main(String... args){ launch(args); } }
You cannot use unicode characters in fxml (specify FA badges if necessary), but can dynamically set attributes with these values. Therefore, having the above enumeration (AwesomeIcon), the work was done:
As a result, I create an Icon Widget / Control / Component to resume the amount of code with two properties:
- value: FA badge name;
- size: the styleable attribute for the
-fx-font-size style on the label.
New code (same effect):
<Icon value="FILE" size="16"/>
The code for this control can be found here . You can also find a working example, as it includes a font and test code.
Nuno Rafael Figueiredo
source share