将comboBox更改为自动完成文本字段代号为1

时间:2014-09-25 23:07:58

标签: combobox autocomplete codenameone

我需要为自动完整文本字段更改一个组合框,但我不知道如何为自动完成文本字段构建渲染。所以...我有一个带渲染的组合,组合填充了来自数据库的数据。当我单击某个选项时,组合框返回一个对象。有效,但我无法控制组合的大小,所以我需要更改为文本字段。

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;
    }

}

http://i.stack.imgur.com/LAgij.png

http://i.stack.imgur.com/NNe0u.png

1 个答案:

答案 0 :(得分:0)

您不需要渲染器,因为模型会返回字符串,这是自动完成工作所需的字符串。

您需要转换代码,以便您的模型是字符串列表,然后只需添加一个自动完成代码。