我的Java应用程序与以下方法有关的问题:
private void clearFields() {
this.clientComboBox.getSelectionModel().clearSelection();
this.segmentComboBox.getSelectionModel().clearSelection();
this.releaseDatePicker.getEditor().clear();
this.titleTextField.clear();
this.priceTextField.clear();
this.basepriceTextField.clear();
this.descTextArea.clear();
this.vinTextField.clear();
this.daysSlider.setValue(1);
}
当我尝试添加汽车时,没有问题,程序运行完美。 但是,当我尝试单击“编辑”选项时,保存更改后,已编辑行的每一列都设置为空,那我做错了什么?
链接到我的仓库:https://github.com/tomekcm4/wypozyczalnia.git
显然这部分有问题:
this.editColumn.setCellFactory(param -> new TableCell<CarFx, CarFx>() {
Button button = createButton("/icons/edit.png");
@Override
protected void updateItem(CarFx item, boolean empty) {
super.updateItem(item, empty);
if (empty) {
setGraphic(null);
return;
}
if (!empty) {
setGraphic(button);
button.setOnAction(event -> {
FXMLLoader loader = FxmlUtils.getLoader("/fxml/AddCar.fxml");
Scene scene = null;
try {
scene = new Scene(loader.load());
} catch (IOException e) {
DialogsUtils.errorDialog(e.getMessage());
}
CarController controller = loader.getController();
controller.getCarModel().setCarFxObjectProperty(item);
controller.bindings();
Stage stage = new Stage();
stage.setScene(scene);
stage.initModality(Modality.APPLICATION_MODAL);
stage.showAndWait();
});
}
}
});
}
保存按钮如下:
public void addCarOnAction() {
try {
this.carModel.saveCarInDataBase();
clearFields();
} catch (ApplicationException e) {
DialogsUtils.errorDialog(e.getMessage());
}
}