繁体   English   中英

ScalaFX / JavaFX样式表未完全委派

[英]ScalaFX/JavaFX Stylesheet is not delegated completely

因此,我正在尝试向场景中添加样式表。 一切正常,直到我进入场景的第二层。 我有以下style.css:

.label: {
    -fx-font: 16px "Serif";
    -fx-padding: 5;
}

.root {
    -fx-background: cornflowerblue;
    -fx-fill: orchid;
}

我设法通过以下代码将其附加到场景中:

private val mainLayout = new BorderPane() {...} // stylesheet missing
private val baseLayout = new StackPane() { // root element, has stylesheet
  children.add(mainLayout)
  ...
}
private val scene: Scene = new Scene(baseLayout) {
  stylesheets.add("style.css") // stylesheet works, but I can only style root
}

根样式也可以,但是如果我在调试器中单击各层,则样式表在根元素之后消失。 我的根是StackPane ,其中包含BorderPane BorderPane已经不包含给定的样式表。

我想念什么? 以后添加元素时,样式表是否不委托? 我现在不使用场景生成器,因为我在scala中存在一些宏扩展的依赖问题。

提前致谢


编辑

解决问题:我的样式表具有样式根和标签。 我创建场景:

var label: Label = new Label()
label.setText("Hello World!")
private val root = new StackPane() {
  children.add(label)
}
private val scene: Scene = new Scene(root) {
  stylesheets.add("style.css")
}

根样式起作用,标签保持不变。 在此处输入图片说明

我正在使用scalafx库,因此我所有的fx类型都来自该库( scalafx.scene.layout.Labelscalafx.scene.Scene等)

好的。 抱歉。 我发现了错误:我在CSS的label标记后添加了一个冒号。 我没有IDEA终极版,所以没有CSS支持,这就是为什么我没有注意到。 现在可以了。 正确的CSS应该看起来像这样:

.label {
    -fx-font: 16px "Serif";
    -fx-padding: 5;
}

.root {
    -fx-background: cornflowerblue;
    -fx-fill: orchid;
}

暂无
暂无

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

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