jIconFont

Home GitHub Project Download

jIconFont - JavaFX

jIconFont-JavaFX is a API to provide icons generated by any IconFont. These icons can be used in JavaFX.

Maven dependency

<dependency>
    <groupId>com.github.jiconfont</groupId>
    <artifactId>jiconfont-javafx</artifactId>
    <version>1.0.0</version>
</dependency>

Usage

Example 1

IconFontFX.register(FontAwesome.getIconFont());

IconNode iconNode = new IconNode(FontAwesome.SMILE_O);
iconNode.setIconSize(40);
iconNode.setFill(Color.DARKGREEN);

Example 2

IconFontFX.register(FontAwesome.getIconFont());

IconNode iconNode = new IconNode(FontAwesome.SMILE_O);
iconNode.setIconSize(18);

Label label = new Label("Hello!");
label.setGraphic(iconNode);

Example 3

IconFontFX.register(FontAwesome.getIconFont());

IconNode iconNode = new IconNode(FontAwesome.FLOPPY_O);
iconNode.setIconSize(15);
iconNode.setFill(Color.BLACK);

Button button = new Button();
button.setGraphic(iconNode);

Example 4

IconFontFX.register(FontAwesome.getIconFont());

IconNode iconNode = new IconNode(FontAwesome.FLOPPY_O);
iconNode.setIconSize(15);
iconNode.setFill(Color.BLACK);

Button button = new Button("Save");
button.setGraphic(iconNode);

Example 5 (Stacked Icons)

IconFontFX.register(FontAwesome.getIconFont());
IconFontFX.register(Elusive.getIconFont());

IconNode iconNode1 = new IconNode(FontAwesome.DATABASE);
iconNode1.setIconSize(26);
iconNode1.setFill(Color.BLACK);

IconNode iconNode2 = new IconNode(Elusive.REMOVE);
iconNode2.setIconSize(14);
iconNode2.setFill(Color.RED);
iconNode2.setStroke(Color.WHITE);

StackedIconNode stackedIconNode = new StackedIconNode(iconNode1);
stackedIconNode.add(Pos.BOTTOM_LEFT, iconNode2);

Example 6 (CSS)

.myClass{
-fx-icon-size: 48px;
-fx-icon-code: "FontAwesome:F25B";
-fx-fill: gray;
}
IconFontFX.register(FontAwesome.getIconFont());

IconNode iconNode = new IconNode();
iconNode.getStyleClass().add("myClass");

Example 7 (Custom font)

IconFontFX.register(new IconFont() {
    @Override
    public String getFontFamily() {
        return "MyCustomFont";
    }

    @Override
    public InputStream getFontInputStream() {
        return MyClass.class.getResourceAsStream("/myCustomFont.ttf");
    }
});

IconNode iconNode = new IconNode();
iconNode.setIconCode(new DefaultIconCode("MyCustomFont", '\u1234'));

Example 8 (Custom font + CSS)

.myCustomClass{
-fx-icon-size: 48px;
-fx-icon-code: "MyCustomFont:1234";
-fx-fill: red;
}
IconFontFX.register(new IconFont() {
    @Override
    public String getFontFamily() {
        return "MyCustomFont";
    }

    @Override
    public InputStream getFontInputStream() {
        return MyClass.class.getResourceAsStream("/myCustomFont.ttf");
    }
});

IconNode iconNode = new IconNode();
iconNode.getStyleClass().add("myCustomClass");

Example 9 (Image)

IconFontFX.register(FontAwesome.getIconFont());

Stop[] stops = new Stop[]{new Stop(0, Color.YELLOW), new Stop(1, Color.RED)};
LinearGradient fill = new LinearGradient(0, 0, 0, 1, true, CycleMethod.NO_CYCLE, stops);
Color stroke = Color.BLACK;
Image image = IconFontFX.buildImage(FontAwesome.SMILE_O, 80, fill, stroke);

Label label = new Label();
label.setGraphic(new ImageView(image));

License

jIconFont is distributed under the terms of the MIT license.