I have a JComboBox with a custom model which extends DefaultComboBoxModel.
When I want to add an item to my combo box I add it to the model and repaint the JComboBox. However, this is leaving the internal field:
selectedItemReminder
unchanged. What should I be doing instead.
I'm not sure I understand what it is you are trying to achieve, but I might be temptered to modify the method to read more like...
The other issue I can see is you seem to be thinking that the list is
1
based, it's not, it's0
based, that is, the first element is0
Updated based on changes to the question
From what I can understand,
intervalAdded
andcontentsChanged
of theJComboBox
check to see if the selected value in the combo box model has changed, if it has, it callsselectedItemChanged
which fires appropriate events to signal the change of the selected item...I would, when you change the model, set the currently selected item value to something like
null
BEFORE you fire any event notifications...So, using the previous example, I would do something more like...