简体   繁体   English

Javafx CSS解析错误

[英]Javafx CSS Parsing Error

Hello currently I am working on adding a css file to my application in order to customize the interface more. 您好,目前我正在为自己的应用程序添加一个CSS文件,以进一步自定义界面。 However I am experiencing an error while parsing the CSS file. 但是,我在解析CSS文件时遇到错误。 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. 下面是错误,CSS文件和CSS文件的导入。

Import 进口

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

CSS 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 . 您需要引用字体名称,因为它包含空格,并使用-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): -fx-font具有多个值时,它期望第一个是字体大小(因此,它期望一个数字):

.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. 有关字体设置的详细信息,请参见JavaFX CSS文档

Try to use this 尝试使用这个

mapScene.getStylesheets().add("/mapScene.css"); mapScene.getStylesheets()。add(“ / mapScene.css”);

Also you have to use px in -fx-font-size 另外,您必须在-fx-font-size中使用px

Like -fx-font-size :12px; 像-fx-font-size:12px;

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM