通过增加许多条目来提高JCombobox的性能 [英] Increase performance of JCombobox with many entries

查看:49
本文介绍了通过增加许多条目来提高JCombobox的性能的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我希望这个问题值得,但我会尝试一下...

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

我有一个相当复杂的GUI,并且希望提高整体性能.我偶然发现了一些组合框,其中填充了很多条目(最多10000行). 所有swing元素的创建都已经过优化,因此通常只初始化一次.但是,假设10个组合框模型总是在后台具有10k项,这似乎有点占用大量内存.

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.

我已经实现了搜索功能,因此用户可以键入"B",并且列表跳至以"B"开头的第一个条目(如果添加了更多字符,则进一步优化).但这不会改变模型,只需重置选定的索引,因此列表仍包含所有条目.

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.

我的问题是:

是否有关于如何处理组合框中的大量条目的最佳实践? 从用户的角度来看,您是希望显示所有条目,还是仅按一个键后按需显示前100个条目?

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:

是否最好在内存中保留一个较大的组合框模型,或者在用户每次输入新密钥时创建一个较小的组合框模型(约有100个条目)?

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?

感谢您的输入和建议!

推荐答案

我将添加例如前100个项目,再添加一个项目更多..."或显示全部".当用户单击该项目时,将加载所有10k记录.另外,如果用户开始输入,我会减去合适的范围(但不要超过100),并在列表中显示出来.

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.

这篇关于通过增加许多条目来提高JCombobox的性能的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆