CSS+JavaFX: Could not resolve X while resolving lookups for Y

吃可爱长大的小学妹 提交于 2020-01-24 00:36:08

问题


I'm brand new to CSS, and trying to make a MWE for a chart in JavaFX. I've been able to make it work in some cases, but my problems pop up when I try to define variables in root. What I want to do eventually is update the values of chart0-color and chart1-color in code, but for now I'm trying to just define them as variables in the .css.

I ran it through CSSLint and it gave some warnings about adjoining classes, but no errors.

If I replace -chart0-color and -chart1-color with any other color string like red or green, the problem goes away.

Do you see any problems in my css?

dummy.css:

.root{
    -chart0-color: #ff0000;
    -chart1-color: #00ff00;
}

.default-color0.chart-legend-item-symbol { -fx-background-color:    -chart0-color;}
.default-color0.chart-series-line {-fx-stroke:                      -chart0-color;}
.default-color0.chart-series-area-line {-fx-stroke:                 -chart0-color;}
.default-color0.chart-series-area-fill {-fx-fill:                   -chart0-color;}

.default-color1.chart-legend-item-symbol { -fx-background-color:    -chart1-color;}
.default-color1.chart-series-line {-fx-stroke:                      -chart1-color;}
.default-color1.chart-series-area-line {-fx-stroke:                 -chart1-color;}
.default-color1.chart-series-area-fill {-fx-fill:                   -chart1-color;}

CSSAreaChartMWE.java:

package csstest;

import java.util.function.Function;

import javafx.application.Application;
import javafx.collections.FXCollections;
import javafx.collections.ObservableList;
import javafx.scene.Scene;
import javafx.scene.chart.AreaChart;
import javafx.scene.chart.NumberAxis;
import javafx.scene.chart.XYChart;
import javafx.scene.chart.XYChart.Series;
import javafx.scene.layout.VBox;
import javafx.stage.Stage;

public class CSSAreaChartMWE extends Application {

    private ObservableList<XYChart.Data<Number, Number>> functionToData(Function<Double, Double> f, double minx, double maxx) {
        ObservableList<XYChart.Data<Number, Number>> list = FXCollections.observableArrayList();

        double dx = (maxx-minx)/(100);
        double x = minx;

        while (x < maxx) {
            list.add(new XYChart.Data<>(x, f.apply(x))); x+=dx;
        }
        return list;
    }


    @Override
    public void start(Stage primaryStage) throws Exception {

        double minx = 0;
        double maxx = 6*Math.PI;
        double amp = 5;
        double period = (maxx-minx)/6;

        Series<Number, Number> sin = new Series<>("sin", functionToData((x) -> amp*Math.sin(x/period), minx, maxx));
        Series<Number, Number> cos = new Series<>("cos", functionToData((x) -> amp*Math.cos(x/period), minx, maxx));


        ObservableList<Series<Number, Number>> series = FXCollections.observableArrayList();
        series.add(sin);
        series.add(cos);

        NumberAxis xAxis = new NumberAxis();
        NumberAxis yAxis = new NumberAxis();
        AreaChart chart = new AreaChart(xAxis, yAxis, series);
        chart.getStylesheets().add(getClass().getResource("dummy.css").toExternalForm());
        chart.setStyle("chart1-color: black; chart2-color: red");

        VBox box = new VBox();
        box.getChildren().add(chart);
        Scene scene = new Scene(box);

        primaryStage.setScene(scene);
        primaryStage.show();

    }

    public static void main(String [] args) {
        launch(args);
    }

}

and finally, the errors:

WARNING: Could not resolve '-chart0-color' while resolving lookups for '-fx-fill' from rule '*.default-color0.chart-series-area-fill' in stylesheet file:/*****/csstest/dummy.css
Jan 31, 2019 6:01:09 PM javafx.scene.CssStyleHelper calculateValue
WARNING: Could not resolve '-chart0-color' while resolving lookups for '-fx-stroke' from rule '*.default-color0.chart-series-area-line' in stylesheet file:/*****/classes/csstest/dummy.css
.......

来源:https://stackoverflow.com/questions/54470598/cssjavafx-could-not-resolve-x-while-resolving-lookups-for-y

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!