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.

3 Answers 3

3

Use String.equals to compare String content. The == operator compares Object references.

if (x.equals("Assigned")) {
Sign up to request clarification or add additional context in comments.

Comments

2

You can't compare Strings with ==, use equals()

1 Comment

Yes thats true, i forgot about that. Its working now, thanks a lot man :) That was indeed a silly mistake :(
1

Use String.equals(). The == operator compares if two Strings reference the same String object; not if they have equal characters in the String.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.