Created
July 22, 2014 17:14
-
-
Save mansueli/03ddfcac16a561de1c86 to your computer and use it in GitHub Desktop.
Glyph Label (Font Awesome) - http://stackoverflow.com/questions/24881816/javafx-8-scenebuilder-2-and-controlsfx-with-fontawesome
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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"/> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment