-
FEATURED COMPONENTS
First time here? Check out the FAQ!
hello i have combobox with autodrop but the autocomplete is doing in case sensitive style i would like be in case insensitive what i am doing wrong there is a workaround thanks a lot.
my code
<combobox id="tc04" autodrop="true" mold="rounded" disabled="true" readonly="true" width="120px" onSelect='handleOnSelect(self);' onCreate='loadAutocompletableComboBox(self,C01);' onAfterRender='onAfterRenderCombobox(self);' buttonVisible="false"/>
Hi
You need to implement your sub model
Comparator comparator = new Comparator() {
public int compare(Object text, Object item) {
String val = text.toString();
String itemText = item.toString();
return itemText.toLowerCase().startsWith(val.toLowerCase()) ? 0 : 1;
}
};
ListModels.toListSubModel(new ListModelList(list), comparator, 20);
hi jimmyshiau could you post a little more code i mean which class i need to implement this? something like this
public class MyModel extends ListModel implements Comparator<MyModel>
or something thanks a lot..
i have solved using this by another post.
OK, more or less I found a solution to this. Since overwriting SimpleListModel.getSubModel() you can control how the matching is done, it's possible to do a non case-sensitive matching, preventing the user from pressing shift key. Something like this should work, use this SimpleListModelExt class to create a ListModel and feed your combobox.
public class SimpleListModelExt extends SimpleListModel {
public SimpleListModelExt(List data) {
super(data);
}
public ListModel getSubModel(Object value, int nRows) {
final String idx = value == null ? "" : objectToString(value);
if (nRows < 0)
nRows = 10;
final LinkedList data = new LinkedList();
for (int i = 0; i < getSize(); i++) {
if (idx.equals("")
|| entryMatchesText(getElementAt(i).toString(), idx)) {
data.add(getElementAt(i));
if (--nRows <= 0)
break; // done
}
}
return new SimpleListModelExt(data);
}
@Override
public boolean entryMatchesText(String entry, String text) {
return entry.toLowerCase().startsWith(text.toLowerCase());
}
}
Asked: 2013-11-05 13:06:33 +0800
Seen: 53 times
Last updated: Nov 27 '13