jIconFont

jIconFont - Swing

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

Maven dependency

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

Usage

Example 1

IconFontSwing.register(FontAwesome.getIconFont());

Icon icon = IconFontSwing.buildIcon(FontAwesome.SMILE_O, 40, new Color(0, 150, 0));
JLabel label = new JLabel(icon);

Example 2

IconFontSwing.register(FontAwesome.getIconFont());

JLabel label = new JLabel("Hello!");
Icon icon = IconFontSwing.buildIcon(FontAwesome.SMILE_O, 18);
label.setIcon(icon);

Example 3

IconFontSwing.register(FontAwesome.getIconFont());

Icon icon = IconFontSwing.buildIcon(FontAwesome.FLOPPY_O, 15);
JButton button = new JButton(icon);

Example 4

IconFontSwing.register(FontAwesome.getIconFont());

JButton button = new JButton("Save");
Icon icon = IconFontSwing.buildIcon(FontAwesome.FLOPPY_O, 15);
button.setIcon(icon);

Example 5 (Custom font)

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

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

IconCode iconCode = new DefaultIconCode("MyCustomFont", '\u1234');
Icon icon = IconFontSwing.buildIcon(iconCode, 40, new Color(0, 150, 0));
JLabel label = new JLabel(icon);

License

jIconFont is distributed under the terms of the MIT license.