首页 文章

Java FX场景构建器无法识别css自定义颜色常量(或变量)

提问于
浏览
1

如果Defined css是plain,则场景构建器使用定义的样式呈现控件...

但如果使用css自定义颜色常量,场景构建器会将控件呈现为白色...

当我运行应用程序时,为场景正确应用了样式(这由javaFX库完成)

note: 链接场景构建器中的css文件与 preview > Scene StyleSheets > add a StyleSheet 是隐含的,这就是基本样式表(没有css颜色常量)工作的原因 .

My Question is:

我该怎么做(场景构建器)理解 CSS(color constants) styles

CSS:

.root {
   -color1: #1BA1E2;
   -color2: #F8F8F8;

   -primary-color: -color1;
   -secondary-color: -color2;
}

.windowbox {
    -fx-border-radius: 50 0 50 0;
    -fx-background-radius: 50 0 50 0;
    -fx-background-color: -primary-color;
}

.lbl {
    -fx-background-color: derive(-primary-color, -10%);
    -fx-text-fill: -secondary-color;
}

上面的css在执行期间(在运行时)完美地工作,但是场景构建器忽略了样式

1 回答

  • 1

    在Scene Builder中,选择 Preview ,然后选择 Scene Style Sheets ,然后选择 Add a Style Sheet ,如here所述 . 然后选择.css文件 . 要获得更多信息,请使用CSS Analyzer功能 .

    此外,由于您的示例使用了css类选择器("."),因此请务必引用fxml中的样式类(例如,styleClass = "lbl") .

    或者,您可以使用css id选择器("#") . 使用该方法,您可以在fxml中指定id(id = "lbl") . 或者您可以从fxml中省略id属性,默认情况下,fx:id值将用作css id选择器(fx:id = "lbl") .

    一些信息herehere .

相关问题