Styling a TableView in CSS (JavaFX)

2020-05-18 17:13发布

问题:

How can I style the "THIS" point in my TableView?

My CSS Code looks as follows:

   */*
 * Empty Stylesheet file.
 */

.root{
    -fx-background-color: #262626;
}

.table-view{
   -fx-background-color: transparent;
}

.table-view:focused{
    -fx-background-color: transparent;
}

/* Spaltenköpfe
    Struktur column-header-background -> column-header */

.table-view .column-header-background{
    -fx-background-color: linear-gradient(#131313 0%, #424141 100%);
}

.table-view .column-header-background .label{
    -fx-background-color: transparent;
    -fx-text-fill: white;
}

.table-view .column-header {
    -fx-background-color: transparent;
}

.table-view .table-cell{
    -fx-text-fill: white;
}

.table-row-cell{
    -fx-background-color: -fx-table-cell-border-color, #616161;
    -fx-background-insets: 0, 0 0 1 0;
    -fx-padding: 0.0em; /* 0 */
}

.table-row-cell:odd{
    -fx-background-color: -fx-table-cell-border-color, #424242;
    -fx-background-insets: 0, 0 0 1 0;
    -fx-padding: 0.0em; /* 0 */  
}

.table-row-cell:selected {
    -fx-background-color: #005797;
    -fx-background-insets: 0;
    -fx-background-radius: 1;
}

.table-view > .virtual-flow > .scroll-bar:vertical,
.table-view > .virtual-flow > .scroll-bar:vertical > .track,
.table-view > .virtual-flow > .scroll-bar:vertical > .track-background, 
.table-view > .virtual-flow > .scroll-bar:horizontal,
.table-view > .virtual-flow > .scroll-bar:horizontal > .track,
.table-view > .virtual-flow > .scroll-bar:horizontal > .track-background {
    -fx-background-color: transparent;
}



.table-view > .virtual-flow > .scroll-bar > .increment-button, 
.table-view > .virtual-flow > .scroll-bar > .decrement-button {
    -fx-opacity: 0;
}*

So as you can see I've already changed the colum-header-background and everything like this. Also I#ve changed the background of the TableView. So I really don't know what exactly I should change in my CSS. Thanks for every help! :)

-GhostfaceChilla-

回答1:

.table-view .filler is the selector you are looking for. The scenic view tool is pretty good for analyzing a component.



回答2:

.table-view{
   -fx-background-color: transparent;
}

Background color can be white if no records in TableView. And maybe nice to have styling for placeholder



回答3:

In case anyone came here searching for CSS of column-show-hide button, here is the CSS.

.table-view .show-hide-columns-button {
    -fx-background-color: red;
    -fx-border-color: -fx-box-border;
    -fx-border-insets: -1 -1 0 0;
}


回答4:

I managed to solve this with this CSS code:

.table-view .filler {
    -fx-border-insets: 10 //Enter value depending on thickness;
}