How can I replace certain words in ComboBox model? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 12

How can I replace certain words in ComboBox model?

https://stackoverflow.com/q/51376283/10005675 I have created a ComboBox which contains some codename like (AJ2000). As soon as I check a Checkbox , it would show(MJ2000). Is there any method of doing this , since ComboBox model does not have replace kind of method.

17th Jul 2018, 8:14 AM
Siddharth Golecha
Siddharth Golecha - avatar
3 Answers
+ 8
I got the answer from stack overflow MyItem[] items= new MyItem[] { new MyItem("test1",1),new MyItem("test2",2),new MyItem("test3",3),new MyItem("test4",4)}; DefaultComboBoxModel<MyItem> defaultComboBoxModel=new DefaultComboBoxModel<MyItem>(items); JComboBox<MyItem> jComboBox=new JComboBox<MyItem>(defaultComboBoxModel); defaultComboBoxModel.addElement(new MyItem("test5", 5)); // changing the combo box label by changing the main data array for(MyItem item:items) { if(item.getName().contains("test")) { item.setName(item.getName().replaceAll("test","array item")); } } // changing the combo box label by changing the Model Object value for(int i=0;i<defaultComboBoxModel.getSize();i++) { if(defaultComboBoxModel.getElementAt(i).getName().contains("test")) { defaultComboBoxModel.getElementAt(i).setName(defaultComboBoxModel.getElementAt(i).getName().replaceAll("test", "other item")); } }
17th Jul 2018, 9:24 AM
Siddharth Golecha
Siddharth Golecha - avatar
+ 5
Ezeome Ugo Depends on which IDE you are working.
25th Jul 2018, 2:47 AM
Siddharth Golecha
Siddharth Golecha - avatar
0
how do you start coding
24th Jul 2018, 9:12 PM
Ezeome Ugo