You are using one of the utility constructors for JList, which takes an array. The List is backed by a ListModel. The utility constructor uses the following to create an implementation of an AbstractListModel:
new AbstractListModel() {
public int getSize() { return listData.length; }
public Object getElementAt(int i) { return listData[i]; }
}
where listData
would be your data
set. You can do the same and pass it into dataList.setModel()
. You might be best served, if this is for more than just a prototype, by creating your own, full-blown implementation of ListModel.
For reference, here is the JList tutorial from Sun.
JComboBox is a bit simpler, as the DefaultComboBoxModel
class has a constructor that takes an array of Object
as a parameter. To replace the data there, you can simply call:
myComboBox.setModel(new DefaultComboBoxModel(data));