• Post Reply Bookmark Topic Watch Topic
  • New Topic

Changing Combo box Model

 
Hasnain Javed
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.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 remove 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.
 
Tim McGuire
Ranch Hand
Posts: 820
IntelliJ IDE Tomcat Server VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
DefaultComboBoxModel already implements MutableComboBoxModel. The removeItemAt(int) method should work for a model of this type. The error you describe would result if you are not explicitly creating a model but just adding data straight into a JComboBox.
Instead you should create a model and then apply that model to your comboBox like so: myCombo.setModel(myDefaultComboBoxModel)

here is some example code:
 
Hasnain Javed
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you very Mr.Mcguire. Problem Solved. I had the same solution in mind but was not sure about it. Thank you very much for your kind response.
Regards.
Hasnain.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!