0

I am currently using netbeans GUI drag and drop form, i have a combobox, and i want the combobox value to change based on data received from a database. The other textboxes are receiving their data correcly, the main problem is with the combobox.

   String x = tI.getStatus();

   if(x == "Assigned"){
       cboStatus.setSelectedIndex(0);
   }
   else if(x == "In progress"){
       cboStatus.setSelectedIndex(1);
   }
   else if (x == "Pending"){
       cboStatus.setSelectedIndex(2);
   }
   else if(x == "Completed"){
       cboStatus.setSelectedIndex(3);
   }

can anyone tell me how to change the index of the combo box based on data received from database. thanks.

4

3 回答 3

3

用于String.equals比较字符串内容。==操作员比较引用Object

if (x.equals("Assigned")) {
于 2013-04-14T16:44:20.617 回答
2

您不能将字符串与 进行比较==,请使用equals()

于 2013-04-14T16:44:38.817 回答
1

使用String.equals(). 运算符比较==两个字符串是否引用同一个字符串对象;如果它们在字符串中具有相同的字符,则不会。

于 2013-04-14T16:45:55.330 回答