I have a perfectly normal ArrayList<MyObject>
that I need to edit and pick an object from.
In the application window, I have a JComboBox
to select the appropriate choice from the list. I'm writing an editor dialog for these objects, which just includes a JList
of these objects and editor fields. It's easy enough to do; I'll just have a ListModel
implementation of some kind. Stick the ArrayList
in, access it through the usual fields. The stuff in the GUI list is 1:1 representation of the stuff in the actual list. Easy.
But the combo box in the main application window is giving me a bit of a headache, because I need a special value. Ideally, the first item in the list should be "(None)", and return a null
.
Do I just need to write some sort of weird ComboBoxModel
implementation for this, or is there an easier, already implemented way to do this? I'd definitely imagine this sort of situation has cropped up before.