Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/342.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何在TableView JavaFX的TableColumn中添加两个按钮_Java_Javafx - Fatal编程技术网

如何在TableView JavaFX的TableColumn中添加两个按钮

如何在TableView JavaFX的TableColumn中添加两个按钮,java,javafx,Java,Javafx,我想在action TableColumn中添加两个按钮,我已经阅读了这两个按钮,但它们都在setGraphic中使用了一个按钮,因此当我尝试使用时: actionFld.setCellFactory(param -> new TableCell<Patient, Patient>() { private final JFXButton editButton = new JFXButton("edit"); private final JFXButton del

我想在action TableColumn中添加两个按钮,我已经阅读了这两个按钮,但它们都在
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
    }
});
actionFld.setCellFactory(参数->新建TableCell()){
私有最终JFXButton编辑按钮=新JFXButton(“编辑”);
私有最终JFXButton deleteButton=新JFXButton(“删除”);
@凌驾
受保护的void updateItem(患者,布尔值为空){
super.updateItem(患者,空);
如果(患者==null){
设置图形(空);
返回;
}
deleteButton.setOnAction(事件->{
Patient getPatient=getTableView().getItems().get(getIndex());
System.out.println(getPatient.getNom()+“”+getPatient.getPrenom());
});
editButton.setOnAction(事件->{
Patient getPatient=getTableView().getItems().get(getIndex());
System.out.println(getPatient.getNom()+“”+getPatient.getPrenom());
});

setGraphic(deleteButton);//您可以使用
HBox
将组件一个接一个地添加,例如:

HBox pane = new HBox(deleteButton, editButton);
setGraphic(pane);
结果:



如果您有其他方法,我会很高兴的!

您可以使用
HBox
一个接一个地添加组件,例如:

HBox pane = new HBox(deleteButton, editButton);
setGraphic(pane);
结果:



如果你有其他方法,我会很高兴的!

如何使用fxml?我想使用旋转的
标签将垂直标题添加到
表格列中
使用
VBox
包含
Label
。找到它:
如何使用fxml?我想使用旋转的
Label
将垂直标题添加到
TableColumn
中。在java中,我只使用
setGraphic()
VBox
包含
Label
。找到它: