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]
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.
Try to use this
mapScene.getStylesheets().add("/mapScene.css");
Also you have to use px in -fx-font-size
Like -fx-font-size :12px;
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.