本文介绍了JavaFX风格的所有相同类型的节点,例如,VBox的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有很多fxml文件包含不同类型的javafx节点,如VBox等。我想知道是否可以添加一个样式表到场景中,自动应用于所有VBox元素声明任何位置在我的项目或甚至以编程方式创建)。我知道按钮很容易支持,因为我可以在我的自定义.css文件中使用.button {...}并将其添加到场景。但是,我找不到任何类似的解决方案,许多节点类型,如VBox,HBox,等等。

I have lots of fxml files containing different types of javafx nodes such as VBox, etc. I want to know if it is possible to add a stylesheet to the scene which automatically applies on all VBox elements declared any where in my project (or even created programatically). I know that it is easily supported for buttons, since I can use .button {...} inside my custom .css file and add it to the scene. However, I can't find anything similar solution for lots of node types such as VBox, HBox, and so on.

我在modena中找到像VBox这样的CSS标签.css放在标准jdk的jfxrt.jar内部。不幸的是,我找不到这样的标签。我也找不到任何例子在oracle的网站太。

I looked for such css tags like VBox inside modena.css which is placed somewhere inside standard jdk's jfxrt.jar. Unfortunately, I could not find such tags. I could not find any example on the oracle's website too.

有没有什么办法这样做?
感谢您的帮助。

Is there any way of doing so?Thanks for your helps.

推荐答案

我自己找到了一个解决方案。您可以像下面这样将一个窗格(如VBox)的简单类名添加到.css文件中:

I myself found a solution. You can add this simple class name of a pane such as VBox to your .css file like this:

HBox, VBox {
    //css instructions here
    -fx-background-color: red;
}

请注意,名称区分大小写;在名称之前不需要点。

Note that names are case sensitive; No dot is required before the name.

这篇关于JavaFX风格的所有相同类型的节点,例如,VBox的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-18 02:14