/ / Cómo agregar dos botones en una columna de tabla de TableView JavaFX - java, javafx

Cómo agregar dos botones en una columna de tabla de TableView JavaFX - java, javafx

Quiero agregar dos botones en la acción TableColumn, ya leí esto Cómo agregar botón en la vista de tabla de JavaFX y esto Agregar un botón a una celda en un TableView (JAVAFX) pero ambos usan un botón en setGraphic, entonces cuando trato de usar:

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
}
});

me muestra un solo botón:

solo un botón

¿Como puedó resolver esté problema?

Respuestas

2 para la respuesta № 1

Puedes usar HBox para agregar su componente uno al lado del otro, por ejemplo:

HBox pane = new HBox(deleteButton, editButton);
setGraphic(pane);

resultado:

HBox


Si tienes otra forma, me alegraré por ello!