JavaFX ListView
The ListView is a container for a list of items. If there are more items in the list than can be
shown, the list scrolls.
The items in the list can be set through the list's "items" property which is an instance of an
"ObservableList".
If we want to know which item in the list is selected, we can ask the list of its selection model and
from that model ask for the selected index or selected item.
For example:
list.getSelectonModel().getSelectedIndex();
If we want to know when a selection changes, we can use the "selectedItemProperty" of the
selection model and add a listener to it.
list.getSelectionModel().selectedItemProperty().addListener(new ChangeListener …);
The ChangeListener has a method called changed:
changed(Observable<? extends T> observable, T oldValue, T newValue)
The visualization for an entry in the list is controlled by the "CellFactory". This is a property
on the List that can be set. JavaFX provides some existing instances including:
• CheckBoxCellList
• ChoiceBoxCellList
• ComboBoxCellList
• TextFieldCellList
The default visualization of a list entry is simply the string representation of the item contained
within. We can define our own visualizer using the "setCellFactory()" method. This
method takes a Callback() object that must return an instance of a ListCell object. It is this
object that is the visualization and describes how to show data.
See also:
• JavaFX ObservableList
• JavaFX MultipleSelectionModel - How items are selected
• JavaFX ListView Tutorial - 8
JavaFX PasswordField
The PasswordField widget is a text entry box which hides the characters typed.
JavaFX ProgressBar
The ProgressBar widget shows the progress of some activity.
Page 270
Kommentare zu diesen Handbüchern