0

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:

enter image description here

Frank
  • 521
  • 7
  • 19
  • Almost certainly a duplicate of the referenced question: if you had written a [MCVE] I would know for sure. If it's different, edit the question with your code and I will reopen. – James_D Sep 21 '15 at 00:15
  • My apologies. I did Google this question for some time, but obviously with the wrong keywords I got sidetracked by an Oracle example for cellfactory where they use: if (item != null) but obviously empty is not null! – Frank Sep 21 '15 at 01:35
  • No worries.. `item==null` and `empty` may or may not be equivalent, depending on your `items` list and on your `cellValueFactory`. It's always helpful to create a [MCVE] though. – James_D Sep 21 '15 at 02:00

0 Answers0