【问题标题】:Settext from selected combobox javafx从选定的组合框 javafx 中设置文本
【发布时间】:2015-10-14 16:47:00
【问题描述】:

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

【问题讨论】:

    标签: java javafx combobox textfield


    【解决方案1】:

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

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

    【讨论】:

    • 感谢您的回答我一直在按照您的要求进行处理,但如果我单击 cmbmapel,我无法在 txtguru 中显示文本
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2011-10-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-10-13
    • 2018-05-24
    相关资源
    最近更新 更多