Reputation: 289
I have a TableView clear. I have an button1, when I click this I added a row in my tableView and I select the row. This row is in red by the line css :
.table-row-cell:selected {-fx-background-color: red;}
Next, I have a button2, and I would like that when I click on the button2, the background color on my row selected change in blue.
Help me.
Thanks.
Upvotes: 2
Views: 3466
Reputation: 2880
You have many ways for changing the values of properties in css from java code.
You can define a look-up color in css and use setStyle()
method in java like that :
.table-view {
-selected-color:red;
}
.table-row-cell:selected{
-fx-background-color: -selected-color;
}
Then use setStyle()
method :
button2.setOnAction(e -> table.setStyle("-selected-color:blue;"));
Upvotes: 0
Reputation: 1077
add this code into your .css file:
#blue_cell .table-row-cell:selected{
-fx-background-color: blue;
}
then add this into your java file
button2.setOnAction(e -> productsTable.setId("blue_cell"));
Upvotes: 2