JavaFX 2.1 TableView 刷新项 [英] JavaFX 2.1 TableView refresh items

查看:71
本文介绍了JavaFX 2.1 TableView 刷新项的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有这个常见的问题,看起来就是这样.重置后,我的表视图不会刷新我的项目.我查了资料,是新的.

I have this common issue, as it appears to be. My table view wont refresh my items after I reset them. I have checked the data and it's the new one.

我从互联网上尝试了多种解决方案,但都没有成功.

无法重置所有列,因为它添加了一个空的一个额外的(不知道为什么)并且调整大小会中断.

Can't reset all the columns because it adds one empty one extra (dont know why) and the resize just breakes.

我的表格不可编辑.新数据已更改.

My table is not editable. The new data is changed.

如果我更改项目的顺序并且行更改 (:|),则会刷新数据.

The data is refreshed if I change the ordering of the items and the rows change (:|).

我只是没有想法.

目前刷新代码非常简单.

At the moment the refresh code is pretty simple.

ObservableList<User> data = FXCollections.observableArrayList(User.getResellers());
reseller_table.setItems(data);

再次确认新数据是正确的.当我对 tableView 进行选择时,它会返回新的正确项目.

Again the new data is correct. When I make an selection to the tableView it returns the new correct Item.

推荐答案

我遇到了类似的刷新问题.我的解决方案是将 ObservableList 上的操作限制为那些与 bind() 一起正常工作的操作.

I had a similar problem with refreshing. My solution was to restrict the operations on the ObservableList to those which work correctly with bind().

假设 ObservableList obsListTableView 的底层列表.

Assume ObservableList obsList is the underlying list for the TableView.

然后
obsList.clear()(继承自java.util.List<>)将不更新TableView正确但是.

Then
obsList.clear() (inherited from java.util.List<>) will not update the TableView correctly but.

也调用 setItem(obsList) 没有不起作用来触发刷新...但是...

Also calling setItem(obsList) did not work to trigger a refresh...but...

obsList.removeAll(obsList)(被 ObservableList 覆盖)工作正常,因为它正确地触发了 changeEvent.

obsList.removeAll(obsList) (overwritten by ObservableList) works fine because it fires the changeEvent correctly.

用全新的内容重新填充列表然后工作如下:

Refilling a list with completely new content then works as follows:

  • obsList.removeAll(obsList);
  • obsList.add(...);//例如.在循环中...

  • obsList.removeAll(obsList);
  • FXCollections.copy(obsList, someSourceList)

这篇关于JavaFX 2.1 TableView 刷新项的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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