Managing ListView items

The ListView content is backed up by an ObservableList and any changes to this list are automatically reflected in the ListView, as in the button handler in the next example:

// chaptep10/list/ListViewDemo.java
ObservableList<String> items = FXCollections.observableArrayList(
"Red", "Blue", "Yellow", "Green");
ListView<String> list = new ListView<>(items);

Button btn = new Button("Add New Item");
btn.setOnAction((e) -> {
items.add(
// just a way to generate semirandom new items
items.get(new Random().nextInt(items.size()))
);
});
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.144.9.169