【发布时间】:2015-04-08 20:51:54
【问题描述】:
美好的一天。当我删除带有按钮的行(自定义 TableCell)时,该行被删除,但里面带有按钮的 TableCell 不会。我怎样才能将它与行一起删除?
当一行被删除时会发生这种情况:
格式化列:
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);
}
});
}
还有 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);
}
}
}
感谢您的宝贵时间。
【问题讨论】:
-
@James_D,对不起。我没有看到这个问题。