Reputation: 895
I'm trying to change color of selected items in ListView with CSS.
.contact-list-cell:selected {
-fx-background-color: green;
}
.list-view:focused .contact-list-cell:selected {
-fx-background-color: green;
}
But it works only when parent ListView looses focus.
I know that standard JavaFX Caspian theme uses .list-view:focused .list-cell:focused:selected:etc{...}
selectors. But I just can't find simple combination that will do the thing.
Upvotes: 4
Views: 5302
Reputation: 209225
The default stylesheet modena.css defines colors in terms of "looked-up colors". The best way to change the style is to override the definitions of these looked-up colors:
.list-view {
-fx-selection-bar:green ;
}
will change the selected, focused color. If you additionally want to change the selection color when not focused, you can do
.list-view {
-fx-selection-bar:green ;
-fx-selection-bar-non-focused: green ;
}
Upvotes: 4
Reputation: 895
As always it is better to view actual sources than to read documentations. In JavaFX 8 caspian.css I have found the solution:
.list-view:focused > .virtual-flow > .clipped-container > .sheet > .contact-list-cell:focused {
-fx-background-color: green;
}
Upvotes: 0