2012-10-05 3 views
5

나는 tableview를 가지고 있고 행의 기본 색을 바꾸고 싶다면 ...
1. 행 위를 가리 킵니다.
2. ... 행을 선택했습니다.
TableView의 행 색상을 변경하는 방법은 무엇입니까?

모든 것을 CSS 파일에서 쉽게 할 수 있습니까?

내가 발견 모든

는 경우 1, 나는 CSS 파일에

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

을 설정할 수 있다는 것입니다. 그걸로 세포의 색깔은 바뀌지 만 전체 줄의 색깔은 변하지 않습니다.

내가 시도한 다른 많은 조합은 작동하지 않습니다.

답변

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 첫 번째 섹션에서'focused'를 제거했지만'.table-view : focused .table-row-cell : filled : selected'라고 읽습니다. 그 이유는 다중 선택이 활성화 된 경우 첫 번째 선택된 행에만 영향을 미치기 때문입니다. –

관련 문제