Bind over the observableList in JavaFx


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?

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

    public void onChanged(javafx.collections.ListChangeListener.Change<? extends Object> change) {
        while ( {
           //If items are removed
           for (Objectremitem : change.getRemoved()) {
           //If items are added
           for (Objectadditem : change.getAddedSubList()) {

Don't forget to take a look at the Javadoc here :

And how to use JavaFX collections here :

7/18/2014 2:27:19 PM

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