Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3874568
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T22:10:00+00:00 2026-05-19T22:10:00+00:00

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

  • 0

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

after you click to somewhere else or click enter,it will conduct the search, 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.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-19T22:10:01+00:00Added an answer on May 19, 2026 at 10:10 pm

    Wow, you’re rebuilding a ComboBoxModel each time ? Isn’t it a little expensive ? You know there is a MutableComboBoxModel, also implemented by DefaultComboBoxModel that would allow you to add/remove elements from you combobox without rebuilding its model each time ?

    Concerning your question, I don’t understand the statement

    However, if i do that, it does perform correctly, however, it will go search for the first item again

    Do you mean your JComboBox starts to blink with content being modified each time ?

    if so, maybe is it because your ActionListener is linked to JComboBox, which content changes continuously.

    Anyway, i suggest you add some logs, like

    sr = new Search(((String) jComboBoxReceiver.getSelectedItem()));    
    DefaultComboBoxModel model = (DefaultComboBoxModel) jComboBoxReceiver.getModel();
    model.remvoeAllElements();
    usrList = sr.searchUser();
    String[] userList = new String[usrList.size()] ;
    for(int i=0;i<usrList.size();i++){
        String username = usrList.get(i).getUserName();
        System.out.println(username); // feel free to instead use one loger
        model.addElement(username);
    }
    

    Besides, i would tend to suggest you an other approach, in which combo box model don’t contain simple Strings, but rather User objects, with a ListCellRenderer displaying only the user name.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to setup code to check the username and password with values in
I'm trying to search through this Json array using PHP: {count:2,items:{milestone:[{id:3107,username:TomSmith1,userid:1620602,date:2012-01-12 16:49:26,projectid:804,projectname:TEST PROJECT,reason:Partial payment
Newbie still learning, been trying to search and hack code together for hours now,
I'm trying to search multiple attributes in XML : <APIS> <API Key=00001> <field Username=username1
I am trying to authenticate user using LDAP I am using this code: public
I'm trying to get json code from page.I use this private function __ajax_admin_search($username =
I am trying to script some code that will search a specified folder on
So here is my code I am trying to compare. What I am trying
While trying to search with id sorting (and paginating) im getting from the log:
Im trying to search two of the fields in my table. (Database table contains

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.