java - ComboBox (setSelectedIndex()) is not working properly -
i have 7 items in combobox , every time when select 1 of them , click "next" button selects first item not next. knows why?
if ("Цена (euro)".equals((string) combobox.getselecteditem())) { if (!"".equals(txtarea.gettext().tostring())) { cenaeuroa = null; string data = (string) txtarea.gettext(); string[] temp = data.split("\n"); cenaeuroa = new string[temp.length]; system.arraycopy(temp, 0, cenaeuroa, 0, temp.length); len = cenaeuroa.length; } combobox.setselectedindex(0); // object sort = "СОРТ"; // combobox.setselecteditem(sort); } txtarea.settext(null);
you selecting first element, combobox.setselectedindex(0). should use getselectedindex() retrieve selected item , use set next.
for example:
final int selectedindex = combobox.getselectedindex(); if (selectedindex < combobox.getitemcount()) { combobox.setselectedindex(selectedindex + 1); }
Comments
Post a Comment