2014-09-25 68 views
1

我需要更改一個自動完成文本字段的組合框,但我不知道如何構建自動完成文本字段的呈現。所以......我有一個渲染組合,組合使用來自數據庫的數據。當我點擊某個選項時,組合框會返回一個對象。作品,但我不能控制組合的大小,所以我需要改變一個文本框。將comboBox更改爲自動完成文本字段codename one

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

回答

0

你並不需要渲染,因爲該模型將返回一個字符串這是你需要什麼自動完成工作。

你需要轉換你的代碼,所以你的模型是一個字符串列表,然後放置一個自動完成。

+0

非常感謝。 – 2014-10-06 21:35:11