javafx - 如何在未聚焦的TableView中设置选定的行文本颜色

时间:2014-02-11 16:16:24

标签: css javafx-2

我的应用使用行选择模式(table.setCellSelectionEnabled(false)

在我的CSS中:

.table-row-cell:selected {
   -fx-background-color: steelblue; 
   -fx-text-fill: red !important;
}

属性-fx-background-color工作正常,但-fx-text-fill没有。所选行的文本颜色为黑色(如果TableView未聚焦)或白色(如果TableView聚焦)。

2 个答案:

答案 0 :(得分:15)

这对我有用,虽然可能有更简单的方法:

.table-row-cell:selected {
   -fx-background-color: steelblue; 
}
.table-row-cell:selected .text {
       -fx-fill: red ;

}

答案 1 :(得分:3)

对于JavaFX 8,基于Modena样式表,所选行文本颜色基于背景亮度(白色表示深色背景,黑色表示浅色背景)。我已经能够通过直接设置文本背景颜色来覆盖它(然后将其用于所选行的文本颜色):

.table-row-cell:selected {
   -fx-background-color: steelblue; 
   -fx-text-background-color: red;
}
相关问题