Bind over the observableList in JavaFx


Question

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
0
7/16/2014 1:44:35 PM

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

1
7/18/2014 2:27:19 PM

Licensed under: CC-BY-SA with attribution
Not affiliated with: Stack Overflow
Icon