JavaFX: Styling application with CSS Selectors

假如想象 提交于 2019-12-03 14:25:17

As you can see in the CSS documentation the HBOX class has no style class defined. Therefore you can't simply use .hbox http://docs.oracle.com/javase/8/javafx/api/javafx/scene/doc-files/cssref.html#hbox

If you want to lookup only direct children of the toolbar the > sign can be used. Using the > sign in a CSS selector will have some benefit in performance issues because by doing so not the complete child hierarchy under the Toolbar Control need to be scanned. Matching Nodes will only be searched in the first hierarchy of children.

So if you want to select all buttons that are direct children of a sidebar you can do the following:

. sidebar > .button

But if you really want to style all button in a sidebar (even if they are wrapped in panes, etc.) you need to use the following selector:

.sidebar .button

Back to your HBOX question: Even if the HBOX has no defined style class (.hbox) it has a type that can be used for a type selector. As described in the CSS doc all nodes have a type:

Node's getTypeSelector method returns a String which is analogous to a CSS Type Selector. By default, this method returns the simple name of the class. Note that the simple name of an inner class or of an anonymous class may not be usable as a type selector. In such a case, this method should be overridden to return a meaningful value.

Because of that the HBOX selector is working.

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