场景:我有一个名为EditClientDeatils.fxm
l 的父窗口,并且TableView
对此有一个。我正在通过创建另一个名为的窗口并将UserDetails.fxml
行数据填充到此 FXML 字段来编辑这些行结果,现在在从我的第二个窗口进行编辑之后,如果我保存,我需要使用最新数据更新父表。我尝试了类似下面而不是彻底刷新桌子。但是当我调试时,我的表格列表会更新为最新的数据,而不是在 Window 中显示。那么如何从不同的控制器更新我的表格视图?
在子窗口中,我正在加载这样的父级。
FXMLLoader fxmlLoader = new FXMLLoader(getClass().getResource("EditClientDetails.fxml"));
EditClientDetailsController fooController = (EditClientDetailsController) fxmlLoader.getController();
try {
fxmlLoader.load();
} catch (IOException ex) {
Logger.getLogger(NewUserController.class.getName()).log(Level.SEVERE, null, ex);
}
在我的父类初始化方法中具有以下代码:
@Override public void initialize(URL url, ResourceBundle rb) {
fNameCol.setCellValueFactory(
new PropertyValueFactory<AtUser, String>("clientFirstName"));
lNameCol.setCellValueFactory(
new PropertyValueFactory<AtUser, String>("clientLastName"));
addressCol.setCellValueFactory(
new PropertyValueFactory<AtUser, String>("clientAddress"));
mobileCol.setCellValueFactory(
new PropertyValueFactory<AtUser, String>("clientMobileNumber"));
emailCol.setCellValueFactory(
new PropertyValueFactory<AtUser, String>("clientEmailID"));
catagoryCol.setCellValueFactory(
new PropertyValueFactory<AtUser, String>("clientTypeCode"));
genderCol.setCellValueFactory(
new PropertyValueFactory<AtUser, String>("gender"));
editSaveAction.setSortable(false);
editSaveAction.setCellValueFactory(
new Callback<TableColumn.CellDataFeatures<AtUser, Boolean>,
ObservableValue<Boolean>>() {
@Override
public ObservableValue<Boolean> call(TableColumn.CellDataFeatures<AtUser, Boolean> p) {
return new SimpleBooleanProperty(p.getValue() != null);
}
});
editSaveAction.setCellFactory(
new Callback<TableColumn<AtUser, Boolean>, TableCell<AtUser, Boolean>>() {
@Override
public TableCell<AtUser, Boolean> call(TableColumn<AtUser, Boolean> p) {
return new ClientButtonCell(customerTable);
}
});
// Add filtered data to the table
customerTable.setItems(filteredData);
// Listen for text changes in the filter text field
filterField.textProperty().addListener(new ChangeListener<String>() {
@Override
public void changed(ObservableValue<? extends String> observable,
String oldValue, String newValue) {
updateFilteredData();
}
});
}
当我调试时
customerTable.setItems(filteredData);
这filteredData
包含我需要的数据,但没有出现在 Window 上。请指出我是否遗漏了什么。