Hernan Acosta wrote:
I can't figure out how to do it. ...
¿How can I add the NONE option?
If the user selects NONE, the selected value has to be NULL. I don't want to add that option to my model, because I don't want to complicate it.
The first element in your myPatients array should be something like "- none -". If it isn't, create a new array that has "- none -" as the first element, then fill in the rest of the elements with your myPatients array.
You don't have to call setSelectedIndex() when you are creating your ComboBox.
Another approach could be to place a JCheckBox to the left of the JComboBox that would both setSelectedIndex(-1) and disable the JComboBox when unchecked.
Whether you initially check the box and enable the combo, or uncheck the box and disable the combo, is up to you. You could also cache the last selected value in an instance field so that if the used accidentally unselects the checkbox, the selection can be restored by checking it again.
There are no new questions, but there may be new answers.
That approach is interesting. In some cases, in my application, it would be useful. But I have a large panel with many swing components. And the people using this application doesn't have much experience with computers, so I want to have a more intuitive UI.