Results 1 to 4 of 4
Like Tree1Likes
  • 1 Post By SRaith

Thread: Help with combo box

  1. #1
    Johanis is offline Senior Member
    Join Date
    Oct 2010
    Posts
    139
    Rep Power
    0

    Red face Help with combo box

    Hello I want to do an if statement that says if the user chooses Female it must do something and if the user chooses Male it must also do something. Help would very much appreciated! here is the code:
    Java Code:
    private void comboBox1MouseClicked(MouseEvent e)
          {
             if (comboBox1 == "Female")
             {
                //do something
             }
             else
             {
                if (comboBox1 == "Male")
                {
                //do something
                }
             }
          }

  2. #2
    SRaith is offline Member
    Join Date
    Oct 2011
    Posts
    14
    Rep Power
    0

    Default Re: Help with combo box

    Java Code:
    if(comboBox1.getSelectedItem().equals("Female") {
        // do something
    } else if(comboBox1.getSelectedItem().equals("Male") {
        // do something
    }
    Fubarable likes this.

  3. #3
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    25

    Default Re: Help with combo box

    • Don't check Strings for equality with ==, but instead use the equals(...) method.
    • Check out and use the "else if" construct.


    edit: as SRaith states above!

  4. #4
    Johanis is offline Senior Member
    Join Date
    Oct 2010
    Posts
    139
    Rep Power
    0

    Default Re: Help with combo box

    Thank you a lot Sraith and Mr Moderator!

Similar Threads

  1. dynamically populate the city combo box based on the values of state combo +ajax+jsp
    By sandy1000 in forum JavaServer Pages (JSP) and JSTL
    Replies: 0
    Last Post: 12-29-2010, 10:00 AM
  2. Combo Box
    By efozdel in forum New To Java
    Replies: 1
    Last Post: 07-07-2010, 03:29 PM
  3. help get the value from the combo box
    By archcavalier in forum Enterprise JavaBeans (EJB)
    Replies: 7
    Last Post: 05-23-2010, 06:03 PM
  4. creation of one combo box form another combo box
    By er.tyagigaurav in forum JavaServer Pages (JSP) and JSTL
    Replies: 0
    Last Post: 12-09-2008, 03:14 PM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •