Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

javafx - How to set selected row text color in not focused TableView

Tags:

css

javafx-2

My app uses row selection mode (table.setCellSelectionEnabled(false))

In my CSS:

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

property -fx-background-color works fine, but -fx-text-fill does not. The text color of selected row is black (if TableView is not focused) or white (if TableView is focused).

like image 489
chabapok Avatar asked Nov 29 '22 00:11

chabapok


2 Answers

This works for me, though there may be easier ways:

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

}
like image 84
James_D Avatar answered Dec 09 '22 21:12

James_D


For JavaFX 8, based on the Modena stylesheet, the selected row text color is based on the brightness of the background (white for dark backgrounds, black for light backgrounds). I've been able to override this by setting the text background color directly (which then gets used for the text color for selected rows):

.table-row-cell:selected {
   -fx-background-color: steelblue; 
   -fx-text-background-color: red;
}
like image 31
TxF Avatar answered Dec 09 '22 23:12

TxF