ListView listView = new ListView(model.listViewItems);
Creating a ListView and Assigning Items to a ListView
The following code snippet, from Listing 6-9, defines and populates the ListView in the StarterApp program:
In addition to the code in the preceding snippet, the following line from Listing 6-1 contains an instance variable from our StarterAppModel class that contains the objects that will be displayed in the ListView:
public ObservableList listViewItems = FXCollections.observableArrayList();
Recall that this is the same instance variable that is populated when clicking a leaf TreeItem in the previous section.
The parameter we provide to the ListView constructor causes the ObservableList named listViewItems in the model to be associated with the ListView. As demonstrated in Step 11 of the previous exercise, if contents of the underlying ObservableList change the ListView is automatically updated to reflect the changes.