2

I hope this question is SO worthy, but I'll give it a try...

I have a rather complex GUI and am looking to increase the overall performance a bit. I stumbled upon some comboboxes that are populated with a lot of entries (up to 10000 lines). The creation of all swing elements is already optimized, so they are normally initialized only once. But it seems kinda memory intensive to have, let's say, 10 combobox models with 10k entries always in the background.

I have implemented a search feature, so the user can type 'B' and the list jumps to the first entry starting with 'B' (and further refining if more chars are added). But this does not alter the model, just reset the selected index, so the list still contains all entries.

My question is:

Are there any best practices on how to handle a lot of entries within a combobox? And from the user's view, would you rather display all entries, or just the first 100 and others on demand after a key was pressed?

Or to ask a more specific question:

Is it better to keep a big comboboxmodel in memory, or to create a small one (with ~100 entries) every time the user enters a new key?

Thanks for input and suggestions!

moeTi
  • 3,884
  • 24
  • 37

4 Answers4

4

I would add e.g first 100 and one more item "More..." or "Show All". When user clicks on the item all the 10k records are loaded. Alternatively if user starts typing I would subtract the suitable range (but again not more than 100) and show them in the list.

StanislavL
  • 56,971
  • 9
  • 68
  • 98
3

10000 entries should not be displayed in a JComboBox. You may use a JTextField with autocompletion. Swingx provides an utility to do this: AutoCompleteDecorator.

You could also display the data in a JXList (from swingx again) and used a JTextField to filter its content.

JList is a component already optimized. Only the displayed data (visible in the scrollpane viewport) are really painted. And for memory optimization the flyweight pattern is used for the cell rendering, there is only one ListCellRendeter for drawing all the cells.

If for some reasons, you have to use a JComboBox. Note that the JCombobox uses a JList to display the data on a Popmenu, so it gets the benefits explained above.

For memory improvement of your model, you may consider to load lazily the data. But it is a bit complicated since you want also autocompletion features. Your autocompletion will have to seacrh in the persisted data.

gontard
  • 28,720
  • 11
  • 94
  • 117
  • the combobox was a customer request, but perhaps I can discuss that. I don't like the AutoComplete textfield because you have to know what you are looking for. In a combobox you can enter some letters and narrow down the entries and choose from the leftovers – moeTi Aug 16 '12 at 09:47
1

How much ram is your application using? does it take too long to load initially?

Desktop/notebook memory is dirt cheap nowadays. If your application is a dedicated/professional one, aka the user will be using it intensively in the foreground, you want to offer your user speed and responsiveness above everything. If it were something like an instant messaging tool, you would want to keep its RAM fingerprint low.

My advice is to keep everything in memory, provided a modest 2012 computer build can handle it.

Edit: from a usability point of view, StanislavL's suggestion appeals to me as well.

Buffalo
  • 3,861
  • 8
  • 44
  • 69
  • 1
    it's a user frontend, so if it is open, it will be used in foreground. it sums up to around 200mb of ram. not too much for today machines, but there's always room for imporvements – moeTi Aug 16 '12 at 09:21
  • making a memory usage improvement could mean giving up speed. if you can get away with that (the load-on-request method is not noticeable), go for it. – Buffalo Aug 16 '12 at 09:27
1

With so many items a ComoBox is not suitable. Your idea of smart search is good, but you should improve it by not prepopulating the CB, but rather load the data asynchrounously while the user is typing and start at least 1 or 2 characters.

Tom Metz
  • 919
  • 6
  • 7
  • the combobox is a request from the customer, so changes are not possible (and I kinda like to select predefined values from a combobox too). But I like the async population, most of the data is in a DB anyways so searching is easy – moeTi Aug 16 '12 at 09:26