JavaFX style all nodes of the same type, e.g., VBox

大憨熊 提交于 2020-01-11 09:56:27

问题


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.

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.


回答1:


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.



来源:https://stackoverflow.com/questions/35290665/javafx-style-all-nodes-of-the-same-type-e-g-vbox

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