Combobox 将组合框更改为自动完成文本字段代码名1
我需要为自动完成文本字段更改一个组合框,但我不知道如何为自动完成文本字段构建渲染。所以我有一个带有渲染的组合,该组合由数据库中的数据填充。当我点击某个选项时,组合框返回一个对象。工作,但我不能控制组合的大小,所以我需要更改为文本字段Combobox 将组合框更改为自动完成文本字段代码名1,combobox,autocomplete,codenameone,Combobox,Autocomplete,Codenameone,我需要为自动完成文本字段更改一个组合框,但我不知道如何为自动完成文本字段构建渲染。所以我有一个带有渲染的组合,该组合由数据库中的数据填充。当我点击某个选项时,组合框返回一个对象。工作,但我不能控制组合的大小,所以我需要更改为文本字段 BarriosDB proDb = new BarriosDB(); Vector vectIma = proDb.ejecutarConsulta("select * from barrios where ciudad_id=" + Consta
BarriosDB proDb = new BarriosDB();
Vector vectIma = proDb.ejecutarConsulta("select * from barrios where ciudad_id=" + Constants.CodigoCiudadActual);
String[] lista = new String[vectIma.size()];
Enumeration enumCate = vectIma.elements();
int count = 0;
findComboBoxDirBarrio(f).setRenderer(new RenderizadorBarrio());
while (enumCate.hasMoreElements()) {
Barrios cate = (Barrios) enumCate.nextElement();
findComboBoxDirBarrio(f).addItem(cate);
}
这是渲染的代码
public class RenderizadorBarrio extends Container implements ListCellRenderer {
private Label texto = new Label("");
private Label focus = new Label("");
public RenderizadorBarrio(){
setLayout(new BorderLayout());
addComponent(BorderLayout.CENTER, texto);
focus.getStyle().setBgTransparency(100);
}
public Component getListCellRendererComponent(List list, Object value, int index, boolean isSelected) {
Barrios ov=(Barrios) value;
this.texto.setText(ov.getNombre());
return this;
}
public Component getListFocusComponent(List list) {
return focus;
}
}
您不需要渲染器,因为模型将返回字符串,这是自动完成工作所需的字符串 您需要转换您的代码,使您的模型是一个字符串列表,然后放置一个自动完成