But what I am try to discuss here, how to create Auto-suggestion JComboBox that suggest any item that start or end with some text. For example:

Auto-suggestion

And how to create that one? We can’t just modified some library huh? Can we modified example from link http://www.orbital-computer.de/JComboBox/ above? May be you can modified from there but that example are too complicated for me.

public void updateModel(String in) {
data.clear();
// lets find any items which start with the string the user typed, and
// add it to the popup list
// here you would usually get your items from a database, or some other
// storage...
for (String s : db)
if (s.startsWith(in))
data.add(s);
super.fireContentsChanged(this, 0, data.size());
// this is a hack to get around redraw problems when changing the list
// length of the displayed popups
cb.hidePopup();
cb.showPopup();
if (data.size() != 0)
cb.setSelectedIndex(0);
}

On line 8, we see that if s start with in, then we add s to data. To create Auto-suggestion JComboBox, you can modify this line to:

if (s.contains(in))

So now you can use that class for Auto-suggestion JComboBox. Here a complete SearchBoxModel class that I’ve modified: