• Post Reply Bookmark Topic Watch Topic
  • New Topic

Searchable JCombobox

 
Dinesh Madushanka
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am developing a java based software connected with a mysql database. I have an Item table in my database. I created a bean class which can keep all item data with it and. Then I loaded each Item data in to its object and fill a Jcombobox. Now I want to search with Item name and get all Item data when selecting that item. I have overidden the toString method to Item name in that class. Is there any way to search my Item objects inside a jcombobox? Thanks.
 
Jarrod Rackley
Ranch Hand
Posts: 30
Chrome Java Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well first welcome to the ranch!

Next, if you put the items into a List or array before you added them to the JComboBox you could iterate over that and search for your item.

The only ways i can think of accessing items in the combo box is to get the selected item or at item at a given index.

If you wanted you could use getItemCount() method to get the number of items and then loop through the items one at a time to find your item.
I don't think that would be good practice though.


Hope that helps.


-Jarrod

 
Tony Docherty
Saloon Keeper
Posts: 3138
72
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can you explain without reference to your current design what you want to happen. For example when the user clicks on an entry in the combox box I want to ...
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!