我有一些数据源的实体。它有对象 Pojo 的列表。可以通过ds.getRows()获取。 我正在努力将 TableView 绑定(bind)到这个列表上。
tblHlp.itemsProperty().bindBidirectional(new SimpleListProperty<>(FXCollections.observableArrayList(ds.getRows())));
当我更改我创建的 ObservableList FXCollections.observableArrayList(ds.getRows())) tableView 也会更改。但是当我更改 ds (ds.getRows) 中的列表时,我想获得相同的效果。有什么想法吗?
最佳答案
我认为你不能这样做。
您可以做的是在您创建的 ObservableList 上添加 ListChangeListener,然后手动管理要在其他列表中添加/删除的项目。例如这样的事情:
ListChangeListener<Object>() {
@Override
public void onChanged(javafx.collections.ListChangeListener.Change<? extends Object> change) {
while (change.next()) {
//If items are removed
for (Objectremitem : change.getRemoved()) {
unfixColumn(remitem);
}
//If items are added
for (Objectadditem : change.getAddedSubList()) {
fixColumn(additem);
}
}
updateHighlightSelection();
}
};
不要忘记查看此处的 Javadoc:http://download.java.net/jdk8/jfxdocs/javafx/collections/ObservableList.html
以及如何在此处使用 JavaFX 集合:http://docs.oracle.com/javafx/2/collections/jfxpub-collections.htm
关于java - 绑定(bind) JavaFx 中的 observableList,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24782280/