我想在操作TableColumn中添加两个按钮,我已经阅读了这个How to add button in JavaFX table view和Add a button to a cells in a TableView (JAVAFX),但他们都在setGraphic
中使用了一个按钮,所以当我尝试使用时:
actionFld.setCellFactory(param -> new TableCell<Patient, Patient>() {
private final JFXButton editButton = new JFXButton("edit");
private final JFXButton deleteButton = new JFXButton("delete");
@Override
protected void updateItem(Patient patient, boolean empty) {
super.updateItem(patient, empty);
if (patient == null) {
setGraphic(null);
return;
}
deleteButton.setOnAction(event -> {
Patient getPatient = getTableView().getItems().get(getIndex());
System.out.println(getPatient.getNom() + " " + getPatient.getPrenom());
});
editButton.setOnAction(event -> {
Patient getPatient = getTableView().getItems().get(getIndex());
System.out.println(getPatient.getNom() + " " + getPatient.getPrenom());
});
setGraphic(deleteButton);//<<<---------------add button 1
setGraphic(editButton);//<<------------------add button 2
}
});
它只显示一个按钮:
我该如何解决这个问题?