2013-05-04 63 views
1

我在組合框中有7個項目,每當我選擇其中一個項目並單擊「下一步」按鈕時,它將選擇第一個項目不是下一個項目。有誰知道爲什麼?組合框(setSelectedIndex())工作不正常

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); 

回答

3

您正在使用comboBox.setSelectedIndex(0)選擇第一個元素。您應該使用getSelectedIndex()來檢索選定的項目並使用它來設置下一個項目。

例如:

final int selectedIndex = comboBox.getSelectedIndex(); 
if (selectedIndex < comboBox.getItemCount()) { 
    comboBox.setSelectedIndex(selectedIndex + 1); 
}