I have created a GUI and have a database located externally in which I fetch data from. I am using the GUI builder in NetBeans to do this. Does anyone know of a simple way t
When trying to add elements dynamically to a combo box, use MutableComboBoxModel.addElement
JComboBox box = new JComboBox(new DefaultComboBoxModel());
....
MutableComboBoxModel model = (DefaultComboBoxModel)box.getModel();
while (rs.next()) {
model.addElement(rs.getString("Name"));
}
To remove all elements you could also do
((DefaultComboBoxModel)box.getModel).removeAllElements();
Using the model methods will fire the necessary changes to update the ui