Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.java.help > #2329
| From | Knute Johnson <nospam@knutejohnson.com> |
|---|---|
| Newsgroups | comp.lang.java.help |
| Subject | Re: Long delay when using JComboBox.setSelectedIndex() ?? |
| Date | 2012-12-05 16:15 -0800 |
| Organization | A noiseless patient Spider |
| Message-ID | <k9oo3i$4gf$1@dont-email.me> (permalink) |
| References | <b396252c-b370-413b-963b-97313f83a30f@googlegroups.com> |
On 12/5/2012 9:27 AM, kedward777@gmail.com wrote:
> Hello,
>
> I am attempting to load 5000 employee items into a jcombobox, and then setSelectedIndex, but I am getting a odd delay in the gui after setting the selectedIndex
>
> 1) If I load the 5000 employee names using a simple vector, it works fine. When I call setSelectedIndex(5), it sets the combobox to the 5th element, very quickly. This works fine:
>
> while ((line = input.readLine()) != null) {
> StringTokenizer st = new StringTokenizer(line, "|");
> lastName = st.nextToken().trim();
> firstName = st.nextToken().trim();
> id = Integer.parseInt(st.nextToken().trim());
> comboBoxItems.add(lastName);}
>
> mybox1.setModel(new javax.swing.DefaultComboBoxModel(model));
> mybox1.setSelectedIndex(5);
>
>
> 2)HOWEVER, if I load an employee object into a mapped vector, and then setSelectedIndex(5), I DO see it instantly set the GUI combobox to the 5th item, BUT then there is a LOOOONG delay in the gui (1 minute or more) before it allows me to do anything further in the gui
>
> while ((line = input.readLine()) != null) {
> StringTokenizer st = new StringTokenizer(line, "|");
> lastName = st.nextToken().trim();
> firstName = st.nextToken().trim();
> id = Integer.parseInt(st.nextToken().trim());
> empBuffer= new Employee(id, lastName );
> map.put(empBuffer.getId()+"",empBuffer );
> count++; }
>
> model.addAll(map.values());
> Collections.sort(model);
> mybox1.setModel(new javax.swing.DefaultComboBoxModel(model));
> mybox1.setSelectedIndex(5);
>
>
> public class Employee implements Comparable {
> private int id;
> private String name;
>
> public Employee(int id, String name) {
> this.id = id;
> this.name = name;
> }
>
> public String getName() {
> return name;
> }
>
> public int getId() {
> return id;
> }
>
> public int compareTo(Object emp) {
> return getName().compareTo(((Employee)emp).getName());
> }
>
> public String toString() {
> return getName()+","+getId();
> }
> }
>
Having created some rather large GUIs that perform poorly, I wouldn't
create a JComboBox with 5000 elements. It is just too many especially
if your computer is not really fast.
Suggestion: Keep your Employee objects in a List of some sort and use
an editable JComboBox that will load names or IDs that match what you
enter. I might wait for two or three letters before stuffing the
JComboBox to keep the list a more reasonable size. If a person entered
a number you could just bring up that Employee.
--
Knute Johnson
Back to comp.lang.java.help | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
Long delay when using JComboBox.setSelectedIndex() ?? kedward777@gmail.com - 2012-12-05 09:27 -0800
Re: Long delay when using JComboBox.setSelectedIndex() ?? kedward777@gmail.com - 2012-12-05 10:08 -0800
Re: Long delay when using JComboBox.setSelectedIndex() ?? Lew <lewbloch@gmail.com> - 2012-12-05 10:35 -0800
Re: Long delay when using JComboBox.setSelectedIndex() ?? kedward777@gmail.com - 2012-12-05 10:46 -0800
Re: Long delay when using JComboBox.setSelectedIndex() ?? Lew <lewbloch@gmail.com> - 2012-12-05 11:31 -0800
Re: Long delay when using JComboBox.setSelectedIndex() ?? Roedy Green <see_website@mindprod.com.invalid> - 2012-12-05 16:16 -0800
Re: Long delay when using JComboBox.setSelectedIndex() ?? Lew <lewbloch@gmail.com> - 2012-12-05 16:34 -0800
Re: Long delay when using JComboBox.setSelectedIndex() ?? Knute Johnson <nospam@knutejohnson.com> - 2012-12-05 16:40 -0800
Re: Long delay when using JComboBox.setSelectedIndex() ?? Lew <lewbloch@gmail.com> - 2012-12-05 16:58 -0800
Re: Long delay when using JComboBox.setSelectedIndex() ?? Roedy Green <see_website@mindprod.com.invalid> - 2012-12-06 15:32 -0800
Re: Long delay when using JComboBox.setSelectedIndex() ?? Lew <lewbloch@gmail.com> - 2012-12-06 18:04 -0800
Re: Long delay when using JComboBox.setSelectedIndex() ?? Knute Johnson <nospam@knutejohnson.com> - 2012-12-05 16:15 -0800
Re: Long delay when using JComboBox.setSelectedIndex() ?? Gene Wirchenko <genew@telus.net> - 2012-12-12 18:15 -0800
csiph-web