5 Replies Latest reply: May 29, 2012 1:43 AM by Nitin Khare RSS

    help required on JComboBox

    Murray9654
      Hi I have 500 customers in the database. I have to display the customer names in a JComboBox so that user will select the customer name. here i have a problem. pulling 500 customers at a time and displaying them in combobox will take time. the customers may even grow up to thousands. so i don't want to display all the customer names at once in the JComboBox. First i want to display 50 names and when customer pulls the scrollbar to the end of the JComboBox popup then i want to add another 50. How can i do this?

      kindly help me in this regard. Thanks in advance.
        • 1. Re: help required on JComboBox
          809259
          Don't use a JComboBox. Use a JTable with a customized model instead.

          UPDATE: you can supply your own model to a JComboBox too.

          Marcos

          Edited by: marcos_aps on 25/05/2012 11:26
          • 2. Re: help required on JComboBox
            Murray9654
            Hi can u explain little bit more on how i can use jtable for my requirement. I am not able to figure out how i can use jtable for my requirement.
            • 3. Re: help required on JComboBox
              809259
              Well, you will have to configure your table to look like a JList, so no header and no grid lines. Of course it won't have a button to select items like a combo box, but the data will be fetched lazily as you want if you provide a custom table model. Regarding custom table models, you can look here:

              http://docs.oracle.com/javase/tutorial/uiswing/components/table.html#data

              Marcos
              • 4. Re: help required on JComboBox
                Murray9654
                Ay suggestions? kindly help me in this.
                • 5. Re: help required on JComboBox
                  Nitin Khare
                  I do not think users would normally prefer to scroll through thousands or more items in a combo box to pick their choice. You may want to redesign your GUI somewhat like splitting the data into categories and use two combos, one for categories and one for the data and populate the data one based on the value selected on the category one. In case splitting like this is not possible then you may consider to apply some filtering in your JComboBox/JTable so that users can select their choice as they type. I guess this may be of some help to you

                  http://www.glazedlists.com/Home

                  http://www.glazedlists.com/documentation/tutorial-100