Bind over the observableList in JavaFx

穿精又带淫゛_ 提交于 2020-01-06 18:37:47

问题


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

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?


回答1:


I don't think you can do it like that.

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

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

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



来源:https://stackoverflow.com/questions/24782280/bind-over-the-observablelist-in-javafx

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