[英]change css variable javafx color
style.css style.css文件
* {
-color : #00A0B1;
-white : #F5F5F5;
-gray : #95A5A6;
-darkGray : #7F8C8D;
-black : #2C3E50;
-abort : #7F8C8D;
}
.root{
-fx-background-color : -white;
-fx-fill-width : true;
-fx-color : -color;
-fx-fill-width : true;
-fx-font-family: 'Segoe UI';
-fx-focus-color : transparent;
-fx-faint-focus-color: transparent;
}
I was hoping to make a color palette such that the -color
variable can be changed. 我希望制作一个调色板,以便可以改变
-color
变量。 Is there a way to change the variable with a javafx controller? 有没有办法用javafx控制器更改变量? many thanks
非常感谢
The colors you have defined globally ( -color
, -white
, -gray
, etc) are called "looked-up colors" (see documentation ). 颜色你已经全局定义(
-color
, -white
, -gray
等)被称为“查到的颜色”(见文档 )。 You can change the value of a looked-up color at runtime using an inline style. 您可以使用内联样式在运行时更改查找颜色的值。 Eg:
例如:
root.setStyle("-color: #ffff00 ;")
will set the value of -color
to yellow, for root
and all the nodes it contains, unless those have a specific value assigned to them (in the language of CSS, looked-up colors are inherited). 将
-color
的值设置为黄色,用于root
及其包含的所有节点,除非它们具有分配给它们的特定值(在CSS的语言中,查找颜色是继承的)。
Note that your CSS however assigns the looked-up color value directly to all nodes (because all nodes match the selector *
). 请注意,您的CSS会将查找的颜色值直接分配给所有节点(因为所有节点都与选择器
*
匹配)。 So you probably just want to define those on the root node, so that nodes will inherit any dynamically-applied value: 所以你可能只想在根节点上定义那些,这样节点就会继承任何动态应用的值:
.root {
-color : #00A0B1;
-white : #F5F5F5;
-gray : #95A5A6;
-darkGray : #7F8C8D;
-black : #2C3E50;
-abort : #7F8C8D;
-fx-background-color : -white;
-fx-fill-width : true;
-fx-color : -color;
-fx-fill-width : true;
-fx-font-family: 'Segoe UI';
-fx-focus-color : transparent;
-fx-faint-focus-color: transparent;
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.