Reputation: 29
I have a comboBox which has a few items in it already. At Run time, I add an item to it, which gets added successfully. But when, at the end of the execution, the JFrame is loaded again, the recently added item isn't present. I used both the methods, using model.addElement() and using additem() and both have the same problem.
Here's the code:
int i = JOptionPane.INFORMATION_MESSAGE;
String a = JOptionPane.showInputDialog(null, "Enter new item", "Add", i);
DefaultComboBoxModel model = (DefaultComboBoxModel)
cmbo0.getModel();
model.addElement(a);
cmbo0.setSelectedItem(a);
Upvotes: 2
Views: 598
Reputation: 2219
At the moment, your combobox only lives as long as your application.
You'll need a permanent datasource that you can write to, i.e. file, database, etc.
Take a look at these links:
Upvotes: 1