Embed ListCell, which displays the image and sets cellFactoryto ListView. The standard oracle tutorial contains an example implementation of a custom list.
You would do something in the following lines:
friends.setCellFactory(listView -> new ListCell<String>() {
private ImageView imageView = new ImageView();
@Override
public void updateItem(String friend, boolean empty) {
super.updateItem(friend, empty);
if (empty) {
setText(null);
setGraphic(null);
} else {
Image image = getImageForFriend(friend);
imageView.setImage(image);
setText(friend);
setGraphic(imageView);
}
}
});
updateItem(...) , , , , , updateItem(...).