javafx tableview detect any change upon any of rows including addition of new one


because I don't really know the sollution. Lets say i have a TableView that holds info about product: description, quantity and the price. Also have a label that shows a sum of prices (times quantity) of all products from a table. Now i want to be notified about any changes that took affect on this component like changes in existing rows or addition of a new one. Is there any listener or sth similar to achieve it?

1/14/2014 12:25:23 PM

Accepted Answer

Usually you construct a TableView by passing an ObservableList to it. Something like this: TableView myTable = new TableView<>(myObservableList);

ObservableList<ClassOfTheObjectsInTheList> myObservableList = FXCollections.FXCollections.observableArrayList(anyNoneObservableCollection);
TableView<ClassOfTheObjectsInTheList> myTable = new TableView<>(myObservableList);

You can add a ListChangeListener to any ObservableList at will by doing:

myObservableList.addListener(new ListChangeListener<ClassOfObjectsInTheList>(){

                public void onChanged(javafx.collections.ListChangeListener.Change<? extends ClassOfObjectsInTheList> pChange) {
                    while( {
                        // Do your changes here
1/15/2014 2:20:08 PM

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