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.

Vaadin lets you build secure, UX-first PWAs entirely in Java.
Free ebook & tutorial.
ComboBox sort
Hei
I have this set of ComboBox:
final ComboBox[] combos = new ComboBox[comboId.length];
A ComboBox gets name:
combos = new ComboBox(comboId);
ComboBoxes are populated from a JSONArray:
for (int i = 0; i < jArray.length(); i++) {
jObject = jArray.getJSONObject(i);
for (int ic = 0; ic < comboId.length; ic++) {
if (!jObject.isNull(comboId[ic])) {
arvoS = jObject.get(comboId[ic]).toString();
combos[ic].addItem(arvoS);
continue;
}
}
}
Question:
Items of four ComboBoxes should be sort.
How to sort Items of a ComboBox to descending order?
An example:
combos[2] [1909, 1914, 1922, 1923, 1926, 1927, 1928, 1929, 1930, 1931, . . . 2007, 2008, 2009, 2010]
Tapani
Hi, Tapani!
ComboBoxes have IndexedContainers by default, so you could add the items in the order you want them. IndexedContainer also happens to implement Container.Sortable, which means that you can use the sort() method in IndexedContainer. (scroll down for the documentation, I can't link directly to it since this forum software doesn't accept ] in URL:s).
HTH,
/Jonatan