javafx treetableview单元格值未更新 [英] javafx treetableview cell value not getting updated

查看:163
本文介绍了javafx treetableview单元格值未更新的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

更新数据模型javafx treetableview单元格值后事件未更新.

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)

在单击按钮时,我试图更新第一项:employee.get(0).setName("Test");

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

是否有任何技巧可以使用更新的treetableview?

Is there any trick using which treetableview can be updated?

推荐答案

该示例有些奇怪,返回了一个ReadOnlyStringWrapper,其中包装了单元格值工厂的属性值.因此,它没有将列中显示的值直接绑定到Employee类中的属性,而是将它们绑定到一个新的只读属性,该属性包装了在单元格上调用updateItem(..)时检索到的值.这意味着在更新基础数据时不会更新,而仅在单元格上调用updateItem(...)方法时才更新. (我不知道他们为什么会这样做.)因此,例如,您应该发现,如果更改值,然后将TreeTableView中的根节点折叠,然后再次展开,则在展开后将显示新值根(因为这会导致调用单元格的updateItem(...)方法).

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).

要使单元格在数据更改时更新,请将单元格值直接绑定到模型(Employee)类中定义的属性:

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());

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

这篇关于javafx treetableview单元格值未更新的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆