6

I have a tableview and want to change the default colors of the rows if I...
1. ... hover above a row.
2. ... selected a row.

Is there a easy way to do all of it in the css-file?

All I found out is that for case 1, I can set

.table-cell:hover { -fx-background-color: green; }

in the css-file. With that the color of the cell changes but not the color of the whole row.

.table-view .row-selection:hover{ -fx-background-color: lightgreen; } and a lot of other combinations I tried are not working.

Sergey Grinev
  • 34,078
  • 10
  • 128
  • 141
marie
  • 155
  • 1
  • 3
  • 7

1 Answers1

20
/* Selected row */
.table-view:focused .table-row-cell:filled:focused:selected {
    -fx-background-color: brown;
    -fx-background-insets: 0, 1, 2;
    -fx-background: -fx-accent;
    -fx-text-fill: -fx-selection-bar-text;
}

/* Selected row when table not focused */
.table-row-cell:filled:focused:selected {
    -fx-background-color: red;
    -fx-background-insets: 0, 1, 2;
    -fx-background: -fx-accent;
    -fx-text-fill: -fx-selection-bar-text;
}

/* Row hovered */
.table-view:row-selection .table-row-cell:filled:hover {
    -fx-background-color: green;
    -fx-background-insets: 0, 0 0 1 0;
    -fx-text-fill: -fx-text-inner-color;
}

/* Selected row hovered */
.table-view:focused .table-row-cell:filled:focused:selected:hover {
    -fx-background: -fx-accent;
    -fx-background-color: yellow;
    -fx-background-insets: 0, 1, 2;
    -fx-text-fill: -fx-selection-bar-text;
}

/* Selected row hovered when table not focused */
.table-view:row-selection .table-row-cell:filled:focused:hover {
    -fx-background-color: blue;
    -fx-background-insets: 0, 0 0 1 0, 1 1 2 1, 2 2 3 2, 3 3 4 3;
    -fx-text-fill: -fx-text-inner-color;
}
Uluk Biy
  • 48,655
  • 13
  • 146
  • 153
  • +1, though I would remove `focused` from the first section so it reads: `.table-view:focused .table-row-cell:filled:selected`. The reason for that is when multiple selection is enabled it only affected the first selected row. – Wojciech Owczarczyk May 10 '13 at 08:38