TilePane: how to create individual event on the buttons

0

I have a hard time using TilePane, I can not create an event for each button in the array. Follow the code for you to help me.

   'TilePane tilePane = new TilePane();
    tilePane.setPrefColumns(3); //preferred columns
    tilePane.setAlignment(Pos.CENTER);

    Button[] buttons = new Button[9];


    for (int j = 0; j < buttons.length; j++) {

        buttons[j] = new Button("" + (""), new ImageView(BUTTON_CLOSE_IMAGE));
        buttons[j].setId("btn_transparent");
        buttons[j].setPrefSize(90, 90);
        tilePane.getChildren().add(buttons[j]);

        // Aqui tenho um layout com nove botões em três colunas, mas quero que cada         //botão tenha um código diferente. como fazer isso?


    }'
    
asked by anonymous 30.04.2015 / 13:30

1 answer

0

I was wrong about where I was putting the event, but making several attempts, I ended up getting:

TilePane tilePane = new TilePane();
tilePane.setPrefColumns(3); //preferred columns
tilePane.setAlignment(Pos.CENTER);

Button[] buttons = new Button[9];


for (int j = 0; j < buttons.length; j++) {

    buttons[j] = new Button("" + (""), new ImageView(BUTTON_CLOSE_IMAGE));
    buttons[j].setId("btn_transparent");
    buttons[j].setPrefSize(90, 90);
    tilePane.getChildren().add(buttons[j]);

}

 buttons[0].setOnAction(e -> System.out.print("oi")); // Minha resposta
    
30.04.2015 / 14:04