ListCell implementation that draws a
ChoiceBox node inside the cell.
By default, the ChoiceBoxListCell is rendered as a Label when not
being edited, and as a ChoiceBox when in editing mode. The ChoiceBox will, by
default, stretch to fill the entire list cell.
To create a ChoiceBoxListCell, it is necessary to provide zero or more
items that will be shown to the user when the ChoiceBox menu is
showing. These items must be of the same type as the ListView items sequence,
such that upon selection, they replace the existing value in the
items list.
| Modifier and Type | Field and Description |
|---|---|
| private ChoiceBox | |
| private ObjectProperty | |
| private final ObservableList |
| Access | Constructor and Description |
|---|---|
| public | |
| public | ChoiceBoxListCell(T...
The items to show in the ChoiceBox popup menu when selected
by the user. items)Creates a default |
| public | ChoiceBoxListCell(StringConverter<T>
A converter, T... StringConverter that can convert an item of type T
into a user-readable string so that it may then be shown in the
ChoiceBox popup menu.The items to show in the ChoiceBox popup menu when selected
by the user. items)Creates a |
| public | ChoiceBoxListCell(ObservableList<T>
The items to show in the ChoiceBox popup menu when selected
by the user. items)Creates a default |
| public | ChoiceBoxListCell(StringConverter<T>
A converter, ObservableList<T> StringConverter that can convert an item of type T
into a user-readable string so that it may then be shown in the
ChoiceBox popup menu.The items to show in the ChoiceBox popup menu when selected
by the user. items)Creates a |
| Modifier and Type | Method and Description |
|---|---|
| public void | cancelEdit()
Overrides javafx. Cancels an edit to the value of the cell. |
| public final ObjectProperty | |
| public static < The type of the elements contained within the ListView. T> Callback | Returns: ACallback that will return a ListCell that is able to
work on the type of element contained within the ListView.Creates a ChoiceBox cell factory for use in |
| public static < The type of the elements contained within the ListView. T> Callback | Returns: ACallback that will return a ListCell that is able to
work on the type of element contained within the ListView.A converter, final T... items)StringConverter to convert the given item (of type T)
to a String for displaying to the user.Creates a ChoiceBox cell factory for use in |
| public static < The type of the elements contained within the ListView. T> Callback | Returns: ACallback that will return a ListCell that is able to
work on the type of element contained within the ListView.An items)ObservableList containing zero or more items that
will be shown to the user when the ChoiceBox menu is showing.
These items must be of the same type as the ListView items sequence,
such that upon selection, they replace the existing value in the
items list.Creates a ChoiceBox cell factory for use in |
| public static < The type of the elements contained within the ListView. T> Callback | Returns: ACallback that will return a ListCell that is able to
work on the type of element contained within the ListView.A converter, final ObservableList<T> StringConverter to convert the given item (of type T)
to a String for displaying to the user.An items)ObservableList containing zero or more items that
will be shown to the user when the ChoiceBox menu is showing.
These items must be of the same type as the ListView items sequence,
such that upon selection, they replace the existing value in the
items list.Creates a ChoiceBox cell factory for use in |
| public final StringConverter | Returns: theStringConverter used in this cellReturns the |
| public ObservableList | Returns: the items to be displayed in the ChoiceBox when it is showingReturns the items to be displayed in the ChoiceBox when it is showing. |
| public final void | setConverter(StringConverter<T>
the value)StringConverter to be used in this cellSets the |
| public void | startEdit()
Overrides javafx. Starts an edit to the value of the cell. |
| public void | updateItem(T item, boolean empty)
Overrides javafx. The updateItem method should not be called by developers, but it is the best method for developers to override to allow for them to customise the visuals of the cell. |
| choiceBox | back to summary |
|---|---|
| private ChoiceBox<T> choiceBox | |
| converter | back to summary |
|---|---|
| private ObjectProperty<StringConverter<T>> converter | |
| items | back to summary |
|---|---|
| private final ObservableList<T> items | |
| ChoiceBoxListCell | back to summary |
|---|---|
| public ChoiceBoxListCell() Creates a default ChoiceBoxListCell with an empty items list. | |
| ChoiceBoxListCell | back to summary |
|---|---|
| public ChoiceBoxListCell(T... items) Creates a default
| |
| ChoiceBoxListCell | back to summary |
|---|---|
| public ChoiceBoxListCell(StringConverter<T> converter, T... items) Creates a
| |
| ChoiceBoxListCell | back to summary |
|---|---|
| public ChoiceBoxListCell(ObservableList<T> items) Creates a default
| |
| ChoiceBoxListCell | back to summary |
|---|---|
| public ChoiceBoxListCell(StringConverter<T> converter, ObservableList<T> items) Creates a
| |
| cancelEdit | back to summary |
|---|---|
| public void cancelEdit() Overrides javafx. Doc from javafx. Cancels an edit to the value of the cell. Call this function to transition from an editing state into a non-editing state, without saving any user input.
| |
| converterProperty | back to summary |
|---|---|
| public final ObjectProperty The
| |
| forListView | back to summary |
|---|---|
| public static <T> Callback Creates a ChoiceBox cell factory for use in | |
| forListView | back to summary |
|---|---|
| public static <T> Callback Creates a ChoiceBox cell factory for use in
| |
| forListView | back to summary |
|---|---|
| public static <T> Callback Creates a ChoiceBox cell factory for use in
| |
| forListView | back to summary |
|---|---|
| public static <T> Callback Creates a ChoiceBox cell factory for use in
| |
| getConverter | back to summary |
|---|---|
| public final StringConverter Returns the
| |
| getItems | back to summary |
|---|---|
| public ObservableList Returns the items to be displayed in the ChoiceBox when it is showing.
| |
| setConverter | back to summary |
|---|---|
| public final void setConverter(StringConverter<T> value) Sets the
| |
| startEdit | back to summary |
|---|---|
| public void startEdit() Overrides javafx. Doc from javafx. Starts an edit to the value of the cell. Call this function to transition from a non-editing state into an editing state, if the cell is editable. If this cell is already in an editing state, it will stay in it.
| |
| updateItem | back to summary |
|---|---|
| public void updateItem(T item, boolean empty) Overrides javafx. Doc from javafx. The updateItem method should not be called by developers, but it is the
best method for developers to override to allow for them to customise the
visuals of the cell. To clarify, developers should never call this method
in their code (they should leave it up to the UI control, such as the
It is very important that subclasses of Cell override the updateItem method properly, as failure to do so will lead to issues such as blank cells or cells with unexpected content appearing within them. Here is an example of how to properly override the updateItem method:
protected void updateItem(T item, boolean empty) {
super.updateItem(item, empty);
if (empty || item == null) {
setText(null);
setGraphic(null);
} else {
setText(item.toString());
}
}
Note in this code sample two important points:
| |