Changing Combo box model
Hello Every One,
I need to create a combo box with the MutableComboBoxModel but didn't understand how to do it from the API sepcification on java.sun.com .The recquirment is that a record has to be deleted by choosing the item from the combo box and after deleting the record, the selected item should also be removed from the combo box. If you try to remove the item with method removeItemAt(int), it throws an exception that the model should be changed to MutableComboBoxModel in order to remove items from the combo box. I hope this clearifies the problem.
Can any one help me with the topic. An early response will be highly Appreciated.
Regards.
Hasnain.
[680 byte] By [
Hasnain] at [2007-11-11 6:34:20]

# 1 Re: Changing Combo box model
Each of the Swing components which display data use a Model to hold/access the data, the UI portion then works to display the data accessed through the Model. Models are implemented through provided Interfaces.
One of the Model Interfaces for the JComboBox is MutuableComboBoxModel. You create a ComboBoxModel class which implements the MutableComboBoxModel interface, then when you create your JComboBox you use the constructor which uses your ComboBoxModel as its argument.
In the "How to Use a ComboBox" portion of the JavaTutorial, you'll see reference to ComboBox2.java. It uses an array of strings as its data source, then the author sets the ComboBox as editable. This did not need to have the full on implementation of a Model - is this what you're looking for, or is your data more complex than this?
nspils at 2007-11-11 22:41:00 >
