Click to See Complete Forum and Search --> : help with JCombox


peace_comp
12-11-2007, 06:20 AM
Peace..
hey ..well I just need to know if there is a special methode in jcomobox to test if an item already exist in the list before we add it..

I could use a sample loop to compare between each Item in the Comobox with the item i wanna add ..(if one of them return a true boolean means that it exist)..but it won't be a good idea if the list is so long ..
but is there already a methode tu use directly to get if a value (or item) exist in the combobox..???

I had this problem when I try put a columns values into a jcombobox (when a user click on a button)..but if he clicks many times the same values are repeated in the list ???
thanks

nspils
12-11-2007, 07:40 AM
The method would not be in the JComboBox itself, but in the "Model" you are using to serve up the data which is displayed in the JComboBox. There are straight-forward ways to determine whether an element exists in the data container before you add that element, and to make sure you are allowing only one - - the standard implementation of a Set, and any container will permit you to generate an Array from the elements in the container to serve as the Model for your JComboBox.