JavaFX and CSS Styling

左心房为你撑大大i 提交于 2019-12-24 17:06:55

问题


I'm kind of new to CSS and was wondering if anyone can answer a questions for me.

In a lot of CSS sample code I see sections like this:

.listview{
   ...
   -fx-background-color: -fx-box-border, -fx-control-inner-background ;
   ...
}

So my question is where do the -fx-box-border, -fx-control-inner-background values come from? They appear to be connstants defined somewhere but where and what are their values?

Thanks in advance.


回答1:


Values such as -fx-background-color are "looked-up colors" defined in the default JavaFX (8) stylesheet, modena.css.

You can find out their values (and many other things) by examining the default stylesheet that ships with your Java Runtime Environment (JRE).

jar xvf $JAVA_HOME/jre/lib/ext/jfxrt.jar com/sun/javafx/scene/control/skin/modena/modena.css 
cat com/sun/javafx/scene/control/skin/modena/modena.css

(Adjust the above command for your installed JRE location if JAVA_HOME is not set in your environment).

Definition of a "looked-up-color", copied from the JavaFX CSS reference guide:

With looked-up colors you can refer to any other color property that is set on the current node or any of its parents. This is a very powerful feature, as it allows a generic palette of colors to be specified on the scene then used thoughout the application. If you want to change one of those palette colors you can do so at any level in the scene tree and it will affect that node and all its decendents. Looked-up colors are not looked up until they are applied, so they are live and react to any style changes that might occur, such as replacing a palette color at runtime with the "style" property on a node.

In the following example, all background color of all buttons uses the looked up color "abc".

.root { abc: #f00 }
.button { -fx-background-color: abc }


来源:https://stackoverflow.com/questions/37492457/javafx-and-css-styling

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