来自所选组合框javafx的Settext

时间:2015-10-14 16:47:00

标签: java javafx combobox textfield

我是JavaFX的初学者我发现很难,当我想要组合框的setTextfield我有2个文件:控制器和工具

 //controller
    @FXML
    public void txtguru(KeyEvent event){
        ArrayList<String>tguru=crud.textguru((String)cmbmapel.getValue());
        txtguru.setText(tguru.toString());
    }

//implement
@Override
    public ArrayList<String> textguru(String a) {
        ArrayList<String>guru=new ArrayList<>();
        try {
            sql="select idguru from mapel where nmmapel like '%"+a+"%'";
            rs=con.connect().createStatement().executeQuery(sql);
            while(rs.next()){
                modelnilai m=new modelnilai();
                m.setguru(rs.getString("idguru"));
            }
        } catch (Exception e) {
            Logger.getLogger(implementnilai.class.getName()).log(Level.SEVERE, null,e);
        }
        return guru;
    }

1 个答案:

答案 0 :(得分:0)

tguru变量始终为空,因为您未在idguru方法中将新提取的guru值添加到textguru。 (听起来像绕口令呀:))。将它们添加为:

@Override
public ArrayList<String> textguru(String a) {
    ArrayList<String>guru=new ArrayList<>();
    try {
        sql="select idguru from mapel where nmmapel like '%"+a+"%'";
        rs=con.connect().createStatement().executeQuery(sql);
        while(rs.next()){
            String idguru = rs.getString("idguru");
            modelnilai m=new modelnilai();
            m.setguru(idguru);
            // Note that you are not using the modelnilai object above
            guru.add(idguru);
        }
    } catch (Exception e) {
        Logger.getLogger(implementnilai.class.getName()).log(Level.SEVERE, null,e);
    }
    return guru;
}