I read this question and get this code from answer:
.list-cell:filled:selected:focused, .list-cell:filled:selected {
/* 3:, 4: */
-fx-background-color: linear-gradient(#333 0%, #777 25%, #aaa 75%, #eee 100%);
-fx-text-fill: white; /* 5 */
}
.list-cell { -fx-text-fill: black; /* 5 */ }
.list-cell:odd { -fx-background-color: white; /* 1 */ }
.list-cell:even { -fx-background-color: #8f8; /* for information */ }
.list-cell:filled:hover {
-fx-background-color: #00f; /* 2 */
-fx-text-fill: white; /* 5 */
}
I would make the selected item with black text-fill (text-color). Therefore I take these classes
.list-cell:filled:selected:focused, .list-cell:filled:selected
and change attribute -fx-text-fill
from white
to black
, but nothing happens, but if I change background color to red, then background color have changed (this does not apply to text color, this is just check on right classes)
How to change text color of selected item in focused ListView?
UPD1:
I tried to change text color of list-cell just in this variant:
.list-cell{
-fx-text-fill: magenta;
}
and this variant:
.list-view:focused > .virtual-flow > .clipped-container > .sheet > .list-cell:filled{
-fx-text-fill: magenta;
}
but nothing works
Best Answer
I tried the following code and it works just fine on Java 8. It changes the text color of the selected cell.
ListViewSample.java
list.css
This also works :