JComboBox 从数据库中检索信息。添加数据后,列表应立即更新。
我知道我需要fireContentsChanged
更新这些值。我不确定我应该在方法中做什么。任何指导将不胜感激!
class ComboModel extends AbstractListModel implements ComboBoxModel
{
ArrayList list = new ArrayList();
@Override
public Object getElementAt(int arg0) {
return null;
}
@Override
public int getSize() {
return list.size();
}
@Override
public Object getSelectedItem() {
}
@Override
public void setSelectedItem(Object arg0) {
}
}
stockListComboBox = new JComboBox();
ComboModel model = new ComboModel();
stockListComboBox.setModel(model);
try
{
// Database stuffs
}
catch(Exception e)
{
e.printStackTrace();
}