在按钮上删除卡单击 JavaFX
Remove card on button click JavaFX
我正在制作一个看板,我在其中有一列,使用 header 和下面的卡片列表之间的网格窗格将其划分。我正在使用场景生成器构建它。
所以层次结构是
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
}
但是当我按下按钮时没有任何反应,卡没有被删除,我不知道为什么。如果有人能帮助我,那就太好了。
尝试按如下方式更改代码:
@FXML
public void delete() {
Parent card = button.getParent();
((VBox) card.getParent()).getChildren().remove(card);
}
我正在制作一个看板,我在其中有一列,使用 header 和下面的卡片列表之间的网格窗格将其划分。我正在使用场景生成器构建它。
所以层次结构是
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
}
但是当我按下按钮时没有任何反应,卡没有被删除,我不知道为什么。如果有人能帮助我,那就太好了。
尝试按如下方式更改代码:
@FXML
public void delete() {
Parent card = button.getParent();
((VBox) card.getParent()).getChildren().remove(card);
}