Javafx Cell with embebed button doesn't remove when remove row

Javafx Cell with embebed button doesn't remove when remove row,javafx,javafx-8,Javafx,Javafx 8,Good day. When i remove a row with a button inside (Customized TableCell), the row is removed, but the TableCell with a button inside don't. How i can remove it with the row? This happen when a row is removed: Formatting the columns: private void initializeTable() { id.setCellValueFactory(cellData -> cellData.getValue().getIdProperty()); names.setCellValueFactory(cellData -> cellData.getValue().getNamesProperty()); surnames.setCellValueFactory(cellData -> ce

Good day. When i remove a row with a button inside (Customized TableCell), the row is removed, but the TableCell with a button inside don't. How i can remove it with the row?

This happen when a row is removed:

Formatting the columns:

private void initializeTable() {
        id.setCellValueFactory(cellData -> cellData.getValue().getIdProperty());
        names.setCellValueFactory(cellData -> cellData.getValue().getNamesProperty());
        surnames.setCellValueFactory(cellData -> cellData.getValue().getSurnamesProperty());
        dni.setCellValueFactory(cellData -> cellData.getValue().getDniProperty());
        birthDate.setCellValueFactory(cellData -> cellData.getValue().getBirthDateProperty());
        address.setCellValueFactory(cellData -> cellData.getValue().getAddressProperty());
        createCellPhone();
        email.setCellValueFactory(cellData -> cellData.getValue().getEmailProperty());
        state.setCellValueFactory(cellData -> cellData.getValue().getActiveProperty());
    }
    private void attachTxtSearchListener() {
        txtSearch.textProperty().addListener((observable, oldValue, newValue) -> {
            if(newValue.isEmpty()) {
                customerList.setAll(customerBak); // restore original cusomer list
            }
        });
    }
    private void createCellPhone() {
        // define a simple boolean cell value for the action column so that the
        // column will only be shown for non-empty rows.
        phones.setCellValueFactory(new Callback<TableColumn.CellDataFeatures<CustomerTblModel, Boolean>, ObservableValue<Boolean>>() {
            @Override
            public ObservableValue<Boolean> call(
                    TableColumn.CellDataFeatures<CustomerTblModel, Boolean> features) {
                return new SimpleBooleanProperty(features.getValue() != null);
            }
        });
        // create a cell value factory with an add button for each row in the table.
        phones.setCellFactory(new Callback<TableColumn<CustomerTblModel, Boolean>, TableCell<CustomerTblModel, Boolean>>() {
            @Override
            public TableCell<CustomerTblModel, Boolean> call(
                    TableColumn<CustomerTblModel, Boolean> booleanTableColumn) {
                return new ButtonCell(THIS, Modality.APPLICATION_MODAL);
            }
        });
    }

And the TableCell:

public class ButtonCell extends TableCell<CustomerTblModel, Boolean> {
    private final StackPane pane = new StackPane();
    private final Button btnPhones = new Button("Teléfonos");

    public ButtonCell(final MainController FATHER, final Modality MODALITY) {
        pane.setPadding(new Insets(3));
        btnPhones.getStyleClass().add("btn-new");
        pane.getChildren().add(btnPhones);
        btnPhones.setOnAction(new EventHandler<ActionEvent>() {
            @Override
            public void handle(ActionEvent event) {
                StageUtil.loadCustomerPhones(FATHER, MODALITY).showAndWait();
            }
        });
    }
    @Override
    protected void updateItem(Boolean item, boolean empty) {
        super.updateItem(item, empty);
        if (!empty) {
            setContentDisplay(ContentDisplay.GRAPHIC_ONLY);
            setGraphic(pane);
        }
    }
}

Thank you for your time.


#1

Cover all cases while updating an item. Try

@Override
protected void updateItem(Boolean item, boolean empty) {
    super.updateItem(item, empty);
    if (!empty) {
        setContentDisplay(ContentDisplay.GRAPHIC_ONLY);
        setGraphic(pane);
    }
    else {
        setText(null);
        setGraphic(null);
    }
}

#2

@James_D, i'm sorry. I doesn't see that question.

#3

Pretty simple and functional. It works fine. Thank you!