2012-10-05 147 views
5

Tengo una vista de tabla y quiero cambiar los colores predeterminados de las filas si ...
1. ... pase el mouse sobre una fila.
2. ... seleccionó una fila.
¿Cómo cambiar los colores de las filas de TableView?

¿Hay una manera fácil de hacer todo esto en el archivo css?

Todo lo que descubrí es que para el caso 1, puedo establecer

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

en el css-archivo. Con eso cambia el color de la celda, pero no el color de toda la fila.

.table-view .row-selection:hover{ -fx-background-color: lightgreen; } y muchas otras combinaciones que probé no funcionan.

Respuesta

16
/* 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; 
} 
+0

+1, aunque eliminaría 'focused' de la primera sección para que diga:' .table-view: focused .table-row-cell: filled: selected'. El motivo es que cuando la selección múltiple está habilitada, solo afectaba a la primera fila seleccionada. –

Cuestiones relacionadas