简体   繁体   English

删除卡上的按钮单击 JavaFX

[英]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);
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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