Javafx 8, scenebuilder 2 and controlsfx with fontawesome?

I am relatively new to javafx and recently started a project using java 8 and javafx. I am using Scenebuilder 2.0 to create javafx ui. I was wondering if anyone managed to use fontenesome in scriptbuilder? I currently need to do this to add graphics to the shortcut

levelLabel1.setGraphic(create(FontAwesome.Glyph.CHEVRON_RIGHT));

public static Node create(Glyph glyph) {
    FontAwesome fontAwesome = new FontAwesome();
    fontAwesome.fontColor(color);

    Node result = fontAwesome.create(glyph.getChar());
    result.setScaleX(SCALE);
    result.setScaleY(SCALE);
    return result;
}
+4
source share
2 answers

You will need to create a custom component .

Then you can download it there (but still you can’t see the glyph there) and you can install the glyphs more easily:

Code is available by default.

Main.java

import org.controlsfx.glyphfont.FontAwesome;
import javafx.application.Application;
import javafx.scene.Scene;
import javafx.scene.layout.Pane;
import javafx.stage.Stage;
public class Main extends Application {

    @Override
    public void start(Stage primaryStage) throws Exception {
       FALabel label = new FALabel();
       label.setGlyph(FontAwesome.Glyph.ANDROID);
       label.setValue("RoBOZUKU");
       Pane p = new Pane();
       p.getChildren().add(label);
       Scene scene = new Scene(p);
       primaryStage.setScene(scene);
       primaryStage.show();
    }
    public static void main(String[] args) {
        launch(args);
    }
}

FALabel.java

import org.controlsfx.glyphfont.FontAwesome;
import org.controlsfx.glyphfont.FontAwesome.Glyph;
import javafx.fxml.FXMLLoader;
import javafx.scene.Node;
import javafx.scene.control.Label;
import javafx.scene.paint.Color;


public class FALabel extends Label{
    private Color color;
    private Glyph glyph;
    public void setValue(String text){
        this.setText(text);
        this.setGraphic(create(getGlyph()));
    }
    public FALabel() {
        FXMLLoader fxmlLoader = new FXMLLoader(getClass().getResource("FALabel.fxml"));
        fxmlLoader.setRoot(this);
        fxmlLoader.setController(this);
        try {
            fxmlLoader.load();
        } catch (Exception exception) {
            throw new RuntimeException(exception);
        }
    }
    public Node create(Glyph glyph) {
        FontAwesome fontAwesome = new FontAwesome();
        fontAwesome.fontColor(getColor());
        Node result = fontAwesome.create(glyph.getChar());
        result.setScaleX(this.getScaleX());
        result.setScaleY(this.getScaleY());
        return result;
    }
    public Color getColor() {
        return color;
    }


    public void setColor(Color color) {
        this.color = color;
    }
    public Glyph getGlyph() {
        return glyph;
    }
    public void setGlyph(Glyph fontAwesome) {
        this.glyph = fontAwesome;
    }
}

FALabel.fxml

<?xml version="1.0" encoding="UTF-8"?>
<?import java.lang.*?>
<?import javafx.scene.control.*?>
<?import javafx.scene.layout.*?>
<fx:root type="javafx.scene.control.Label" xmlns="http://javafx.com/javafx/8" xmlns:fx="http://javafx.com/fxml/1"/>

PS: , , , , , - .

PS2: Awesome Icons ( AnchorPane, Pane, HBox) ImageView .

+3

FontAwesomeFX 8.1, , .

ControlsFx fxml. ()

<?import org.controlsfx.glyphfont.*?>
//...
<Label>
    <graphic>
        <Glyph fontFamily="FontAwesome" icon="PLUS" />
    </graphic>
</Label>
//...
+17

All Articles