Important Notice - Forums is archived

To simplify things and help our users to be more productive, we have archived the current forum and focus our efforts on helping developers on Stack Overflow. You can post new questions on Stack Overflow or join our Discord channel.

Product icon

Vaadin lets you build secure, UX-first PWAs entirely in Java.
Free ebook & tutorial.

How to sort a ComboBox?

Eric B.
1 decade ago Mar 14, 2012 6:55pm
Eric B.
1 decade ago Mar 21, 2012 4:15pm
William Valencia Acosta
1 decade ago Mar 22, 2012 2:38pm
Henri Sara
1 decade ago Mar 22, 2012 3:05pm
Eric B.
1 decade ago Mar 22, 2012 3:41pm
Eric B.
1 decade ago Mar 22, 2012 4:06pm
Charles Anthony
1 decade ago Mar 22, 2012 4:47pm
/* Creating a container, with a property of "name". Item Id is a number, here. Can be anything (unique).
 * Alternatively, you could use the IndexedContainer to generate it's own ItemId :
 * cityContainer.getItem(cityContainer.addItem()).getItemProperty("name").setValue("New York");
IndexedContainer cityContainer = new IndexedContainer();
cityContainer.addContainerProperty("name", String.class, null);
cityContainer.addItem(1).getItemProperty("name").setValue("New York");
cityContainer.getItem(cityContainer.addItem()).getItemProperty("name").setValue("New York");
/* Lets sort the container on ascending name*/
cityContainer.sort(new Object[]{"name"}, new boolean[]{true});

/* Here's a comboBox that uses that container, where we are using the "name" property as the item caption */
ComboBox comboBox = new ComboBox("City", cityContainer);
Last updated on Mar, 22nd 2012
Eric B.
1 decade ago Mar 22, 2012 8:23pm
Rishi Daharwal
8 years ago Sep 13, 2014 4:20pm