java - How I can get an array with 2 items from a selected item in a JComboBox? -
i have arraylist<arraylist<object>> suppliers
. each arraylist<object>
has 2 elements, int (an id , id may not sequential each other.) , string (a name). in jcombobox, create defaultcomboboxmodel, containing main arraylist 'suppliers'.
jcbsuppliers.setmodel (new defaultcomboboxmodel (suppliersdata.suppliers.toarray ()));
the jcombobox shows me each element such [1, local supplier], [2, external supplier], [4, other supplier].
in netbeans debug, put watch on jcbsuppliers. variables window shows me each element of jcbsuppliers arraylist 2 objects.
now question is:
how can these 2 items or array of these 2 objects, of selected object or item?
i appreciate help. thank much.
- first have give kudos flextra , comment spring can decouple code, making easier enhance , debug.
- next suggest re-think current model set up. rather begin nested arraylists, suggest create custom class hold 2 pieces of data each supplier need.
- then create non-nested arraylist of custom class.
- then can tell jcombobox how display object of either giving
tostring()
method displays information you'd it, - or give jcombobox custom cell renderer displays information you'd it.
- then when combo box selected, if selecteditem, object of class, , easy extract 2 pertinent pieces of information.
Comments
Post a Comment