0

So I'm using javafx ListView to represent some data in an application. The content of the listviewis bound like so

ListView<String> listView = new ListView<String>();
Bindings.bindBidirectional(listView.itemsProperty(), new SimpleObjectProperty<>(navigationItem.getItems()));

That way, when navigationItem.getItems() contents changes, the content of the listView does too.

My problem is the following: if there was n items in the lists, they are correctly dispayed, but when updating to less than that (let's say m), the m first are correct, but the n-m last items are the previous ones and are not cleared.

I'm updating my lists like so:

mItems.clear();
mItems.addAll(pItems);

mItems is the list the is returned by navigationItem.getItems().

One more thing, due to the way the ui is handled, I don't have access to the listview after initialization.

Thanks for your help.

ldebroux
  • 147
  • 1
  • 9
  • 1: (This won't solve your problem, but might make your code simpler.) Do you really need this binding? Can't you just do `listView.setItems(navigationItems.getItems())`?. 2. This sounds like a problem with the list cell. Do you have a custom list cell implementation? If so, include it in your question. – James_D Mar 09 '17 at 13:18
  • Hey James, 1) Good point, it make the code simpler. 2) Indeed, I had some old code that was sleeping at the bottom of my class... and that was now useless... Fixed everything, thanks a lot ! – ldebroux Mar 09 '17 at 13:37
  • I'll mark this as duplicate, just because I think it might come up easily in searches and will point other users to the correct fix. – James_D Mar 09 '17 at 13:39

0 Answers0