javafx treetableview cell value not getting updated

我的未来我决定 提交于 2019-12-06 11:45:41

问题


Event after updating the data model javafx treetableview cell value not getting updated.

I am using the sample code here @ http://docs.oracle.com/javase/8/javafx/user-interface-tutorial/tree-table-view.htm (Example 15-2)

On click of button i m trying to update first item: employees.get(0).setName("Test");

Is there any trick using which treetableview can be updated?


回答1:


The example, somewhat strangely, returns a ReadOnlyStringWrapper wrapping the property values for the cell value factories. Thus instead of binding the value displayed in the column directly to the properties in the Employee class, it binds them to a new, read-only, property wrapping the value retrieved when updateItem(..) is called on the cell. This means it won't get updated when the underlying data is updated, but only if the updateItem(...) method is invoked on the cell. (I have no idea why they would do this.) So you should find, for example, that if you change the value, then collapse the root node in the TreeTableView and expand it again, that your new value is displayed after expanding the root (because this causes the cells' updateItem(...) methods to be invoked).

To make the cells update when the data is changed, bind the cell value directly to the property defined in the model (Employee) class:

empColumn.setCellValueFactory( param -> param.getValue().getValue().nameProperty());

and

emailColumn.setCellValueFactory( param -> param.getValue().getValue().emailProperty());


来源:https://stackoverflow.com/questions/23545051/javafx-treetableview-cell-value-not-getting-updated

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!