如何在TableView JavaFX的TableColumn中添加两个按钮 [英] How to add two buttons in a TableColumn of TableView JavaFX
本文介绍了如何在TableView JavaFX的TableColumn中添加两个按钮的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想在操作TableColumn中添加两个按钮,我已经读过这个
我如何解决这个问题?
解决方案
您可以使用 HBox
将组件添加到另一个旁边,例如:
HBox pane = new HBox(deleteButton,editButton);
setGraphic(pane);
结果:
如果您有其他方式,我会很高兴的!
I want to add two button in action TableColumn, i already read this How to add button in JavaFX table view and this Add a button to a cells in a TableView (JAVAFX) but both of them use one button in setGraphic
, so when i try to use :
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
}
});
it show me just one button :
How can i solve this problem?
解决方案
You can use HBox
to add your component one beside the other for example :
HBox pane = new HBox(deleteButton, editButton);
setGraphic(pane);
result:
If you have another way, i will be happy for it!
这篇关于如何在TableView JavaFX的TableColumn中添加两个按钮的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文