【发布时间】:2013-10-03 05:43:05
【问题描述】:
场景:
我有一个名为EditClientDeatils.fxml 的父窗口,并在此上有一个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);
}
在我的父类中初始化方法有以下代码:
@覆盖 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 上。
如果我遗漏了什么,请指出。
【问题讨论】:
-
也就是说不清爽?
-
是的..它不刷新