1919
2020import javafx .beans .property .IntegerProperty ;
2121import javafx .beans .property .ObjectProperty ;
22+ import javafx .beans .property .SimpleStringProperty ;
23+ import javafx .beans .property .StringProperty ;
2224import javafx .css .CssMetaData ;
2325import javafx .css .StyleOrigin ;
2426import javafx .css .Styleable ;
@@ -53,6 +55,7 @@ public class FontIcon extends Text implements Icon {
5355 protected StyleableIntegerProperty iconSize ;
5456 protected StyleableObjectProperty <Paint > iconColor ;
5557 private StyleableObjectProperty <Ikon > iconCode ;
58+ private final StringProperty units ;
5659
5760 public FontIcon () {
5861 getStyleClass ().setAll ("ikonli-font-icon" );
@@ -87,6 +90,8 @@ public FontIcon() {
8790 }
8891 }
8992 });
93+
94+ units = new SimpleStringProperty ("px" );
9095 }
9196
9297 public FontIcon (String iconCode ) {
@@ -99,6 +104,10 @@ public FontIcon(Ikon iconCode) {
99104 setIconCode (iconCode );
100105 }
101106
107+ public StringProperty unitsProperty () {
108+ return units ;
109+ }
110+
102111 @ Override
103112 public String toString () {
104113 Ikon iconCode = getIconCode ();
@@ -133,13 +142,18 @@ public StyleOrigin getStyleOrigin() {
133142 Font font = FontIcon .this .getFont ();
134143 if (Math .abs (font .getSize () - n .doubleValue ()) >= EPSILON ) {
135144 FontIcon .this .setFont (Font .font (font .getFamily (), n .doubleValue ()));
136- FontIcon .this .setStyle (normalizeStyle (getStyle (), "-fx-font-size" , n .intValue () + "px" ));
145+ FontIcon .this .setStyle (normalizeStyle (getStyle (), "-fx-font-size" , n .intValue () + resolveUnits () ));
137146 }
138147 });
139148 }
140149 return iconSize ;
141150 }
142151
152+ private String resolveUnits () {
153+ String u = units .get ();
154+ return null == u || u .isBlank () ? "px" : u ;
155+ }
156+
143157 @ Override
144158 public ObjectProperty <Paint > iconColorProperty () {
145159 if (iconColor == null ) {
0 commit comments