my jComboBox does not react to my keyListener and actionPerform perfroms weired stuff

Posted by aladdin on Stack Overflow See other posts from Stack Overflow or by aladdin
Published on 2011-02-01T15:19:47Z Indexed on 2011/02/01 15:26 UTC
Read the original article Hit count: 232

Filed under:
|

hi

I am trying to search for UserName and return values onto jComboBox, here is the code

public void actionPerformed(java.awt.event.ActionEvent e) {
    sr = new Search(((String) jComboBoxReceiver.getSelectedItem()));    
    usrList = sr.searchUser();
    String[] userList = new String[usrList.size()] ;
    for(int i=0;i<usrList.size();i++){
        userList[i]= usrList.get(i).getUserName();
    }
    model = new DefaultComboBoxModel(userList);
    jComboBoxReceiver.setModel(model);
}

However, if i do that, it does perform correctly, however, it will go search for the first item again, which is very confusing... then i tried using key Pressed

if(e.getKeyCode()==13){
    sr = new Search(((String) jComboBoxReceiver.getSelectedItem()));    
    usrList = sr.searchUser();
    String[] userList = new String[usrList.size()] ;
    for(int i=0;i<usrList.size();i++){
        userList[i]= usrList.get(i).getUserName();
    }
    model = new DefaultComboBoxModel(userList);
    jComboBoxReceiver.setModel(model);
}

And this one does not react at all ...

© Stack Overflow or respective owner

Related posts about java

Related posts about jcombobox