Skip to Main Content

Java SE (Java Platform, Standard Edition)

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Selection change event not fired

se32862378May 10 2013 — edited May 13 2013
So this is my scenario:
I have a list view with a change listener in its selection model:
ObjectProperty<MultipleSelectionModel<MyType>> selectionModelProperty = ...
selectionModelProperty.get().selectedItemProperty().addListener(new ChangeListener<MyType>(){
...
}
When the user clicks certain button, the selected item should be deleted from the list. Also, a new item at the same position of the deleted item should be automatically selected. In case the selected item was the last one, after deletion the new selected item will be the one that was before the deleted one (the new last item in the list).
The code I have looks a bit like this:
int currentIndex = selectionModelProperty.get().getSelectedIndex();
containerList.remove(item); 
if(!containerList.isEmpty()) {
  if(currentIndex == containerList.size()) 
      currentIndex--;
  selectionModelProperty.get().select(currentIndex);
}
This works fine if the item to delete is not the last one. However, if the item to delete is the last one, the change event in the selection model is not triggered !. Is this a bug or an expected behavior ?

I discover that if I clear the selection just before removing the item, a change event in the selection model is correctly fired:
selectionModelProperty.get().clearSelection();

Edited by: se**** on May 11, 2013 1:39 AM
This post has been answered by jsmith on May 13 2013
Jump to Answer
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Jun 10 2013
Added on May 10 2013
5 comments
2,219 views