我想在操作 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
}
});
Run Code Online (Sandbox Code Playgroud)
它只显示一个按钮:
我怎么解决这个问题?
您可以使用HBox将组件添加到另一个组件旁边,例如:
HBox pane = new HBox(deleteButton, editButton);
setGraphic(pane);
Run Code Online (Sandbox Code Playgroud)
结果:
如果你有其他方法,我会很高兴!
| 归档时间: |
|
| 查看次数: |
3924 次 |
| 最近记录: |