JavaFX how to change background color of tableview column using CSS?
12,173
try this and its perfectly worked...
email.setCellFactory(new Callback<TableColumn<CheckDo, String>, TableCell<CheckDo, String>>() {
@Override
public TableCell<CheckDo, String> call(TableColumn<CheckDo, String> p) {
return new TableCell<CheckDo, String>() {
@Override
public void updateItem(String item, boolean empty) {
super.updateItem(item, empty);
if (!isEmpty()) {
this.setStyle("-fx-background-color:red");
setText(item);
}
}
};
Author by
developer
Updated on June 05, 2022Comments
-
developer almost 2 years
With javafx scene builder I hava created a TableView with few editable columns and few non-editable columns. How to set CSS style for non-editable columns, so that the entire column is greyed out. I have created a style class like below and mapped it to table column in javafx scene builder. But it didn't work.
.greyout1 .table-column-cell{ -fx-background-color:rgb(243,243,243); -fx-border-color:rgb(159,159,159); }
Searched the forum, could n't find a solution for styling tableview columns.Could you please suggest an approach?