void (final String[] suggestions) { if(myComboBoxModel == null) return; JComboBox<String> comboBox = (JComboBox<String>) myComponent; final String oldSelectedItem = (String)comboBox.getSelectedItem(); final String oldItemFromTextField = (String) comboBox.getEditor().getItem(); final boolean shouldUpdateTextField = oldItemFromTextField.equals(oldSelectedItem) || oldItemFromTextField.isBlank(); myComboBoxModel.setSuggestions(suggestions); if(suggestions.length > 0 && shouldUpdateTextField) { if (oldSelectedItem != null) { comboBox.setSelectedItem(oldSelectedItem); } else { comboBox.setSelectedIndex(0); } } else { comboBox.getEditor().setItem(oldItemFromTextField); } }