I have a ListView and a Delete button which deletes the currently selected item. My list starts with a vertical scroll bar and I delete the first item. Then I delete the (new) first item again and the scollbar disappears because the list now fits. However from here on the last item will start filling the display - in other words I have the real last item followed by a bunch of phantom items that cannot be selected. As soon as the real last item is cleared, the listview display clears too. This is my delete code:
@FXML
void idBtnDeleteClicked(MouseEvent event) {
final int index = idListView.getSelectionModel().getSelectedIndex();
if (index > -1) {
final int newIndex = (index == idListView.getItems().size() - 1) ? index - 1 : index;
idListView.getItems().remove(index);
idListView.getSelectionModel().select(newIndex);
}
}
Is there another step required such as refresh, reload or ....? Here is an example of the list with some sound effect mp3's: