In this tutorial, I will show you how to use a ListView using JavaFX 21 or later with IntelliJ 2023.2.3 on Windows 11 x64.
The ListView performs basically the same function as a combo box, but it enables the user to choose a single value or multiple values.
lvItems.getItems() Return an ObservableList containing the items to be shown to the user, or null if the items have previously been set to null.
lvItems.getSelectionModel() Returns the currently installed selection model. For the ListView, it will be a multiple selection model so that the user could choose multiple values.
lvItems.getSelectionModel().getSelectedItem() Returns the currently selected object in this lvItems list(which resides in the selected index position).
lvItems.getSelectionModel().getSelectedIndex() Returns the integer value indicating the currently selected index in this model.
lvItems.getSelectionModel().getSelectedIndices() Returns a read-only ObservableList of all selected indices.
drinkList.get(i) Returns the element at the specified position in this drinkList list.
#javafx #listview