Tilepane: how to create individual event on buttons

Asked

Viewed 34 times

0

I have a difficulty using Tilepane, I can’t create an event for each button of 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?


    }`

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

Browser other questions tagged

You are not signed in. Login or sign up in order to post.