java - 在 JavaFX 中更改复选框树项的 CSS 样式
问题描述
我正在使用 JavaFX 8 并有一个treeView填充有复选框树项目,如图所示。我想应用 CSS 以便我可以:
- 更改复选框的背景颜色
- 更改复选框的边框颜色
- 更改复选框内选择图标的颜色
我到处搜索,但无法弄清楚如何做到这一点,并尝试了以下命令的许多变体,但未能使其正常工作。
.tree-view .check-box-tree-cell .check-box {
-fx-background-color: black;
-fx-border-color: orange
}
.tree-view .check-box {
-fx-background-color: black;
-fx-border-color: orange
}
.check-box-tree-cell {
-fx-background-color: black;
-fx-border-color: orange
}
.tree-cell .check-box {
-fx-background-color: black;
-fx-border-color: orange;
}
我该如何解决这个问题?
解决方案
试试这个:
.tree-view .check-box .box {
-fx-background-color: lightskyblue;
-fx-border-color: dodgerblue;
}
.tree-view .check-box:selected .box .mark,
.tree-view .check-box:indeterminate .box .mark {
-fx-background-color: midnightblue;
}
如果您正在使用,这也将起作用CheckBoxTreeCell
:
.check-box-tree-cell > .check-box > .box {
-fx-background-color: lightskyblue;
-fx-border-color: dodgerblue;
}
.check-box-tree-cell > .check-box:selected > .box > .mark,
.check-box-tree-cell > .check-box:indeterminate > .box > .mark {
-fx-background-color: midnightblue;
}
推荐阅读
- c# - SqlException:将 datetime2 数据类型转换为 datetime 数据类型导致值超出范围
- java - 在单选按钮中添加单选按钮,如父子菜单和食物
- jira - 没有可用的命名空间。您必须拥有所有者或维护者权限才能链接命名空间
- python - 尝试将 BeautifulSoup 输出分配给变量以从中获取文本
- sql - 尝试删除 SQL Server 中的重复行,其中差异是日期或批号
- java - VSCode 中的 Java VMOptions
- java - 有什么方法可以从类路径依赖 jar 中的 pom.xml 获取 maven 项目版本
- python - 如何在不同文件中使用基于 tkinter 类的帧刷新 tkinter 帧
- r - 带有aes填充的ggplot2 geom_point仅显示黑色
- javascript - 如何获取跨度中选择了哪个单词