简体   繁体   中英

Remove card on button click JavaFX

I am making a Kanban board, I have a column where inside of it, it's divided using a grid pane between the header and a list of cards below. I am building this using a scene builder.

So the hierarchy is

Anchor Pane(column) -> Gridpane(Seperate header and cards) -> Vbox(where I place my list of cards) -> AnchorPane(cards) -> Button(each card has a button)

When I press the button on the card, I want it to remove the card that I clicked on.

I have done the following

@FXML
public void delete() {
    Parent parent = button.getParent();
    col1.getChildren().remove(parent);  //col1 is the column
}

However nothing happens when I press the button, the card does not get deleted and I do not know why. If someone can help me out that would be great.

Try changing the code as follows:

@FXML
public void delete() {
    Parent card = button.getParent();
    ((VBox) card.getParent()).getChildren().remove(card);
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM