Adam Ren Adam Ren - 1 month ago 26
CSS Question

Javafx CSS Parsing Error

Hello currently I am working on adding a css file to my application in order to customize the interface more. However I am experiencing an error while parsing the CSS file. The application still runs, but I would like to know if this error may cause problems in the future if I leave it and how do I fix it. Below is the error, CSS file and the import of the CSS file.

Import

mapScene.getStylesheets().add(getClass().getResource("mapScene.css").toExternalForm());


CSS

.label{
-fx-font-size: 20;
-fx-font: Times New Roman;
-fx-background-color: #FDFEFE;
}


Error

Oct 16, 2016 7:57:20 AM com.sun.javafx.css.parser.CSSParser declaration
WARNING: CSS Error parsing file:[*PC Location]/bin/gameaspects/mapScene.css: Expected '<number>' while parsing '-fx-font' at [3,17]

Answer

You need to quote the font name, since it contains spaces, and use -fx-font-family. When you have multiple values for -fx-font it is expecting the first to be the font size (hence it is expecting a number):

.label {
    -fx-font-size: 20;
    -fx-font-family: "Times New Roman";
    -fx-background-color: #FDFEFE;
}

See the JavaFX CSS documentation for details on font settings.

Comments