删除卡上的按钮单击JavaFX

我正在制作看板,在其内部有一列,使用标题和下面的卡片列表之间的网格窗格将其划分。我正在使用场景构建器来构建它。

所以层次结构是

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

当我按下卡上的按钮时,我希望它删除我单击的卡。

我已经完成了以下

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

但是,当我按下按钮时什么也没发生,该卡不会被删除,我也不知道为什么。如果有人可以帮助我,那就太好了。

jjyinhua 回答:删除卡上的按钮单击JavaFX

尝试如下更改代码:

@FXML
public void delete() {
    Parent card = button.getParent();
    ((VBox) card.getParent()).getChildren().remove(card);
}
本文链接:https://www.f2er.com/3007037.html

大家都在问