java - Why does JavaFX table.getItems().clear() clear the ObservableList as well -


i've javafx table defined as:

tableview<person> table = new tableview<>; //person class contains firstname,lastname & email properties //table has 3 columns first name, last name & email 

an observablelist of persons

observablelist<person> persons = fxcollections.observablearraylist(); 

a background service, task populate table dynamically adding entries(person objects) observablelist persons.

table binded as:

table.itemsproperty().bind(service.valueproperty()); 

everything working fine... i've found if clear table items by

table.getitems().clear(); 

it not clears table, observablelist persons. i'm wondering if bidirectional binding? if unbind before calling getitems().clear() on table, produces same result. explain point i'm not getting here?

when set itemsproperty of tableview, doing set reference (pointer) stored in property, point specified observablelist, rather making exact copy of specified list.

therefore, when call getitems, returns reference specified list.

therefore, if call clear() on list, clear original observablelist.


note:

in of cases binding have tried not necessary:

table.itemsproperty().bind(service.valueproperty()); 

and enough set itemsproperty

table.setitems(service.valueproperty().get()); 

the binding necessary if plan reference stored in valueproperty point another list in runtime. in of cases enough table gets notifications on changes of list.


Comments

Popular posts from this blog

javascript - Why Selenium can't find an element that is graphically visible -

java - How to compare two classes -

mysql - Gateway Timeout Error on Insert 70000 record using Hibernate in Java -