-1

I'm using a grid pane who contains some buttons. When we clicks on a button it changes the style and I'm implementing a reset button. What I'm trying to do is to apply a specific style when we clicks on that reset button.

Here is my code where I try to get the buttons to apply the default style:

public void displayNewBoard(){
        for (int row = 0; row < GRID_WIDTH; row++) {
            for (int col = 0; col < GRID_HEIGHT; col++) {
                gZone.getChildren().setBackground(new Background(new BackgroundFill(Color.LIGHTGRAY, new CornerRadii(0),new Insets(0))));
            }
        }
    }

gZone is my grid pane and I want to get each button but the line isn't correct.

I also tried an other way:

 for (int row = 0; row < GRID_WIDTH; row++) {
        for (int col = 0; col < GRID_HEIGHT; col++) {
            for (Node node : gZone.getChildren()) {
                if(gZone.getRowIndex(node) == row && gZone.getColumnIndex(node) == col) {
                    node.setBackground(new Background(new BackgroundFill(Color.LIGHTGRAY, new CornerRadii(0),new Insets(0))));
                    break;
                }
            }
        }
    }
J.erome
  • 688
  • 7
  • 26

1 Answers1

0

I finally used an array with all the buttons so I can change them like this :

for (int row = 0; row < GRID_WIDTH; row++) {
        for (int col = 0; col < GRID_HEIGHT; col++) {
            grid[row][col].setBackground(new Background(new BackgroundFill(Color.LIGHTGRAY, new CornerRadii(0),new Insets(0))));
            grid[row][col].setText("");
        }
    }
J.erome
  • 688
  • 7
  • 26