【发布时间】:2017-11-25 13:52:40
【问题描述】:
我想在操作表列中添加两个按钮,我已经阅读了这个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
}
});
它只显示一个按钮:
我该如何解决这个问题?
【问题讨论】: