我有一个带有多个 fxml 文件的 JavaFX 元素(在 NetBeans 中)。有没有办法为每个 fxml 文件分配单独的 css 文件?我想为每个 fxml 进行不同的 .root{...} 设置。可能吗?
最佳答案
将关联的 css
文件添加到每个 FXML
文件:
<stylesheets>
<URL value="@stylesheet.css" />
</stylesheets>
确保 stylesheet.css
位于 CLASSPATH
中。
编辑:如果你想要一个全局css
用于许多fxml
文件,添加fx :id
到您的 fxml
文件中的根 Pane ,并在您的 css
中使用 ID
,root
在默认值中。
#fxml_1 {
... style from the fxml file with fx:id = "fxml_1", and so on
}
关于具有多个 css .root{...} 的 javafx 元素,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16386465/