private void createIndexEvents() {
		selectionModel
                .selectedIndexProperty()
				.addListener((bean, oldVal, newVal) -> {
                    int index = newVal.intValue();
                    ListType item = index == -1 ? null : modelListProperty()
                            .get(index);
                    selectedItem.set(item);
                });
		
		selectedItem.addListener((observable, oldVal, newVal) -> {

            // Item null
            if (newVal == null) {
                selectionModel.select(-1);
                selectedItem.set(null);

            } else {
                int index = modelListProperty().get().indexOf(newVal);
                // Item not found
                if (index != -1) {
                    selectionModel.select(index);
                } else {
                    // If item not found - Rollback
                    selectedItem.set(oldVal);
                }
            }

        });
	}
private void createIndexEvents() {
		selectionModel
                .selectedIndexProperty()
				.addListener((bean, oldVal, newVal) -> {
                    int index = newVal.intValue();
                    ListType item = index == -1 ? null : modelListProperty()
                            .get(index);
                    selectedItem.set(item);
                });
		
		selectedItem.addListener((observable, oldVal, newVal) -> {

            
            if (newVal == null) {
                selectionModel.select(-1);
                selectedItem.set(null);

            } else {
                int index = modelListProperty().get().indexOf(newVal);
                
                if (index != -1) {
                    selectionModel.select(index);
                } else {
                    
                    selectedItem.set(oldVal);
                }
            }

        });
	}
private void createIndexEvents ( ) { selectionModel . selectedIndexProperty ( ) . addListener ( ( bean , oldVal , newVal ) -> { int index = newVal . intValue ( ) ; ListType item = index == - 1 ? null : modelListProperty ( ) . get ( index ) ; selectedItem . set ( item ) ; } ) ; selectedItem . addListener ( ( observable , oldVal , newVal ) -> { // Item null if ( newVal == null ) { selectionModel . select ( - 1 ) ; selectedItem . set ( null ) ; } else { int index = modelListProperty ( ) . get ( ) . indexOf ( newVal ) ; // Item not found if ( index != - 1 ) { selectionModel . select ( index ) ; } else { // If item not found - Rollback selectedItem . set ( oldVal ) ; } } } ) ; }
When the selected item changed we want to set the index property too
When the selected item changed we want to set the index property too