I would like to make in JavaFX a 9x9 sudoku grid like in this image
Any idea how to do it in a nice way? Thanks
Edit: I managed to do it, but the code doesn't look so good.
private void addBackground(StackPane cell, int row, int col) {
String[] colors = {"#b0cbe1", "#cbe183", "#e18398","#b0e183", "#b8778a", "#e198b0", "#b08398", "#cb98b0", "#e1b0cb"};
if(row < 3) {
if(col < 3) {
cell.setStyle("-fx-background-color: " + colors[0] + ";");
} else if (col >= 3 && col < 6 ) {
cell.setStyle("-fx-background-color: " + colors[1] + ";");
} else{
cell.setStyle("-fx-background-color: " + colors[2] + ";");
}
} else if (row >= 3 && row <6) {
if(col < 3) {
cell.setStyle("-fx-background-color: " + colors[3] + ";");
} else if (col >= 3 && col < 6 ) {
cell.setStyle("-fx-background-color: " + colors[4] + ";");
} else {
cell.setStyle("-fx-background-color: " + colors[5] + ";");
}
} else {
if(col < 3) {
cell.setStyle("-fx-background-color: " + colors[6] + ";");
} else if (col >= 3 && col < 6 ) {
cell.setStyle("-fx-background-color: " + colors[7] + ";");
} else{
cell.setStyle("-fx-background-color: " + colors[8] + ";");
}
}
}