I'm trying to make colored toggle buttons to remember their color before they were selected, for example, a black button is selected will be gray, and after it's deselected it will be back to black.
When the buttons are created they are given these properties:
cell.setStyle("-fx-border-color: black; -fx-background-color: gray; -fx-base: gray; -fx-border-width: 1");
cell.setOnAction(event -> setPerformAction(cell));
That's the event:
public void setPerformAction(ToggleButton cell) {
if(cell.isSelected()) {
cell.setStyle("-fx-border-color: red");
}
else{
cell.setStyle("-fx-border-color: black");
}
}
The black and white were applied like this:
cell.setStyle("-fx-base: white; -fx-background-color: white; -fx-border-width: 1");
But as you see in the gif below, when the buttons are deselected, all of them return to a different color. How can they remember their previous color?
BTW those buttons are generated dynamically on runtime so I can't see them in scene builder and they don't have css code.