0

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]

2 Answers 2

3

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.

Sign up to request clarification or add additional context in comments.

Comments

0

Try to use this

mapScene.getStylesheets().add("/mapScene.css");

Also you have to use px in -fx-font-size

Like -fx-font-size :12px;

3 Comments

Unfortunately this does not solve the problem and returns the same error as before. Also it should be\\mapScene.css not /mapScene.css.
@AdamReni did you try using px in font.Also i run fx programs using /.its the same weather you use \\ or /.
I just ran the program and for me its fine.let me check

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.