Is there anyway to add an image to a JavaFX ListView?
This is how I am currently setting the list view items.
private ListView<String> friends;
private ObservableList<String> items;
items = FXCollections.observableArrayList(getFriends);
friends.setItems(items);
I'm also using the list view value as an id to know which was selected.
Implement a
ListCell
that displays the image and set acellFactory
on theListView
. The standard oracle tutorial has an example of a custom list cell implementation.You would do something along the following lines:
The
updateItem(...)
method can be called quite often, so it is probably better to preload the images and make them available to the cell, rather than creating them every timeupdateItem(...)
is called.remember to refresh or load your Listview with myListViewWithPath.setItems(myObserverFilledWithImages);