java JavaFX CSS 警告:CSS 错误解析文件:...:预期 LBRACE 在

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/28973873/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-11-02 14:28:52  来源:igfitidea点击:

JavaFX CSS WARNING: CSS Error parsing file : ... : Expected LBRACE at

javacssjavafx

提问by Cao Felix

I recently ask a question about adding two vertical lines onto the JavaFX LineChart and now I am having issue with applying some style stuffs to the plots. I think this is a new question so I open a new thread.

我最近问了一个关于在 JavaFX LineChart 上添加两条垂直线的问题,现在我在将一些样式内容应用于绘图时遇到了问题。我认为这是一个新问题,所以我打开了一个新线程。

Add Two Vertical Lines to LineChart

向折线图中添加两条垂直线

My question: How can I change different color of the series? I also want to change the background to be white.

我的问题:如何更改系列的不同颜色?我也想把背景改成白色。

The following is the chart that I create (it extends LineChart):

以下是我创建的图表(它扩展了 LineChart):

LineChartWithMarkers<Number, Number> chart = new LineChartWithMarkers<Number, Number>(xAxis, yAxis, dataset);

xAxis.setLabel("time(s)");
yAxis.setLabel("deg/s");

chart.setStyle(".chart-series-line { -fx-stroke-width: 2px; -fx-effect: null; ");
chart.setStyle(".default-color0.chart-series-line { -fx-stroke: blue; }");
chart.setStyle(".default-color1.chart-series-line { -fx-stroke: red; }");
chart.setStyle(".default-color0.chart-line-symbol { -fx-stroke: blue, blue; }");
chart.setStyle(".default-color1.chart-line-symbol { -fx-stroke: red, red; }");
chart.setStyle(".chart-legend { -fx-background-color: transparent; }");

For some reason, those codes won't apply to the chart. So I try to use a CSS file.

出于某种原因,这些代码不适用于图表。所以我尝试使用 CSS 文件。

The following is the CSS file:

以下是CSS文件:

@CHARSET "ISO-8859-1";

.chart-series-line {
-fx-stroke-width: 1px;
-fx-effect: null;}

.default-color0.chart-series-line { -fx-stroke: blue; }
.default-color1.chart-series-line { -fx-stroke: red; }

.default-color0.chart-line-symbol { -fx-background-color: blue, blue; }
.default-color1.chart-line-symbol { -fx-background-color: red, red; }

.chart-legend {
-fx-background-color: transparent;
-fx-font-size: 0.75em;}

.chart-legend-item-symbol{
-fx-background-radius: 2;}

.chart-plot-background {
-fx-background-color: transparent;}

I try to follow Using JavaFX Charts: Styling Charts with CSS, but I get an error in the console is "WARNING: CSS Error parsing file : ... : Expected LBRACE at [1,9]"

我尝试遵循Using JavaFX Charts: Styling Charts with CSS,但我在控制台中收到一个错误是“警告:CSS 错误解析文件:...:预期的 LBRACE 在 [1,9]”

I just switch from JDK 7 to JDK 8 today so I am not sure if it has anything to do with that...

我今天刚从 JDK 7 切换到 JDK 8,所以我不确定它是否与此有关...

Thanks for any help!

谢谢你的帮助!

回答by Adam

The @charsetrule is not supported by JavaFX CSS, which is only a subset of full W3C CSS. Try removing it.

@charset规则不支持JavaFX的CSS,这是唯一的全W3C CSS的一个子集。尝试删除它。

@ Rules

Beginning with JavaFX 8u20, the CSS @import is also partially supported. Only unconditional import is supported. In other words, the media?type qualifier is not supported. Also, the JavaFX CSS parser is non-compliant with regard to where an @import may appear within a stylesheet (see At?rules). Users are cautioned that this will be fixed in a future release. Adherence to the W3C standard is strongly advised.

@规则

从 JavaFX 8u20 开始,还部分支持 CSS @import。仅支持无条件导入。换句话说,不支持 media?type 限定符。此外,JavaFX CSS 解析器不符合 @import 可能出现在样式表中的位置(请参阅 At?rules)。提醒用户,这将在未来版本中修复。强烈建议遵守 W3C 标准。