简体   繁体   中英

How to color custom column exactly like a header in JavaFX?

I would like to simulate database table GUI with JavaFX TableView, which has special column to denote row status. Here is the example from MS Access:

在此处输入图片说明

Hence, I would like to have special column with exact same colors, as the table header. I don't want to guess style explicitly, I wan't it to inherit colors which are already set for a header.

Is it possible?

The default stylesheet uses

-fx-background-color: -fx-box-border, -fx-inner-border, -fx-body-color;
-fx-background-insets: 0, 0 1 1 0, 1 2 2 1;

for the headers. So you could try something like:

.row-header-cell {
    -fx-background-color: -fx-box-border, -fx-inner-border, -fx-body-color;
    -fx-background-insets: 0, 0 1 1 0, 1 2 2 1;
}

.table-row-cell:selected .row-header-cell {
    -fx-body-color: gold ;
}

and then use a cell factory on the "row header" column:

TableColumn<...> rowHeaderColumn = ... ;
rowHeaderColumn.setCellFactory(col -> {
    TableCell<...> cell = new TableCell<>();
    cell.getStyleClass().add("row-header-cell");
    return cell ;
});

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM