本文介绍了绑定到JavaFx中的observableList的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一些数据源的实体.它具有对象Pojo的列表.可以通过ds.getRows()获得.我正在尝试将TableView绑定到此列表上.

I have a entity of some datasource. It has List of object Pojo. It can be get by ds.getRows().I'm trying to bind TableView on this list very hard.

tblHlp.itemsProperty().bindBidirectional(new SimpleListProperty<>(FXCollections.observableArrayList(ds.getRows())));

当我更改创建FXCollections.observableArrayList(ds.getRows())tableView的ObservableList时,也进行了更改.但是当我在ds中更改List(ds.getRows)时,我希望获得相同的效果.有什么想法吗?

When I change that ObservableList which I created FXCollections.observableArrayList(ds.getRows())) tableView is changed too. But I want to get the same effect when I change List in ds (ds.getRows). Any ideas?

推荐答案

我认为您不能那样做.

您可以做的是在创建的ObservableList上添加ListChangeListener,然后手动管理要在其他列表中添加/删除的项目.例如这样的东西:

What you can do is to add a ListChangeListener on the ObservableList you created and then manage manually the items to add/remove in your other list. For example something like that:

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

Don't forget to take a look at the Javadoc here : http://download.java.net/jdk8/jfxdocs/javafx/collections/ObservableList.html

以及如何在此处使用JavaFX集合: http://docs. oracle.com/javafx/2/collections/jfxpub-collections.htm

And how to use JavaFX collections here : http://docs.oracle.com/javafx/2/collections/jfxpub-collections.htm

这篇关于绑定到JavaFx中的observableList的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-15 05:34