更改组合框项目时未加载文本字段

时间:2017-04-04 08:53:34

标签: java swing

当我在组合框中选择一个值时,我遇到了从数据库中显示texfield数据的问题。我只能将组合框中的第一项显示到文本字段中,因为它默认在页面加载时加载。当我从组合框中选择时休息没有任何反应。请帮忙。这是我需要处理的代码中的位置。

cmbProjects = new JComboBox<String>();

cmbProjects.addActionListener(new ActionListener() {
  public void actionPerformed(ActionEvent arg0) {
    try {
      String query= "SELECT * FROM PROJECT WHERE PROJ_NAME = ?";
      PreparedStatement pst= connection.prepareStatement(query);
      pst.setString(1, (String)cmbProjects.getSelectedItem());

      ResultSet rs= pst.executeQuery();
      while(rs.next()){
        textField.setText(rs.getString("PROJ_ID"));
        textField_1.setText(rs.getString("PROJ_WO_NUMBER"));
        textField_2.setText(rs.getString("PROJ_START_DATE"));
        textField_3.setText(rs.getString("PROJ_END_DATE"));
        //JTextArea.setText(rs.getString("PROJ_COMMENTS"));
        textField_4.setText(rs.getString("PROJ_STATUS"));
        textField_5.setText(rs.getString("PROJ_ADDED_BY"));
        textField_6.setText(rs.getString("PROJ_ADDED_ON"));
      }
    }
    catch(Exception ex){

    }
  }
});

cmbProjects.setToolTipText("well");
cmbProjects.setBounds(139, 94, 394, 27);
panelDetails3_1.add(cmbProjects);

0 个答案:

没有答案