Results 1 to 9 of 9
  1. #1
    nksjolinder1 is offline Member
    Join Date
    Oct 2011
    Posts
    9
    Rep Power
    0

    Default Combo Boxes HELP

    So i have two combo boxes declared as such...

    JComboBox supNameText = new JComboBox(supStrings);

    JComboBox empNameText = new JComboBox(empStrings);


    The arrays in them look like this...

    String[] supStrings = { "Jane Smith", "Jerry Yang", "David Hart", "Meg Whitman" };

    String[] empStrings = { "John Doe", "Steward Waddy", "Michael Hart", "Nick Sjolinder" };

    My problem is that i am trying to create an if statement saying that if a certain name is selected in the empNameText combo box, then i want the one that goes along with that to automatically select in the supNameText combo box. For example, if the combo box empNameText has the values blue, red, and yellow to choose from and the combo box supNameText has the values blueberry, strawberry, and banana to choose from, i want the second box to automatically choose blueberry if i choose blue in the first box and so on. How do i do this??? Thanks!

  2. #2
    Junky's Avatar
    Junky is offline Grand Poobah
    Join Date
    Jan 2011
    Location
    Dystopia
    Posts
    3,789
    Rep Power
    7

    Default Re: Combo Boxes HELP

    Have you read the API to see what methods JComboBox has? I bet there are 2 methods that can do what you want.

  3. #3
    nksjolinder1 is offline Member
    Join Date
    Oct 2011
    Posts
    9
    Rep Power
    0

    Default Re: Combo Boxes HELP

    API? i've looke at getSelectedItem and get Selected index but i dont think they were what i wanted

  4. #4
    Junky's Avatar
    Junky is offline Grand Poobah
    Join Date
    Jan 2011
    Location
    Dystopia
    Posts
    3,789
    Rep Power
    7

    Default Re: Combo Boxes HELP

    Yes the Java API where all the classes and their methods are listed as well as explanations of what they do. I would imagine getSelectedIndex is exactly what you want.

  5. #5
    nksjolinder1 is offline Member
    Join Date
    Oct 2011
    Posts
    9
    Rep Power
    0

    Default Re: Combo Boxes HELP

    When i type:

    if (empNameText.getSelectedIndex() = 0)

    It doesnt work work.

  6. #6
    nksjolinder1 is offline Member
    Join Date
    Oct 2011
    Posts
    9
    Rep Power
    0

    Default Re: Combo Boxes HELP

    like i know to continue the if statement but it already has an error

  7. #7
    Junky's Avatar
    Junky is offline Grand Poobah
    Join Date
    Jan 2011
    Location
    Dystopia
    Posts
    3,789
    Rep Power
    7

    Default Re: Combo Boxes HELP

    "it doesn't work" provides zero information.

    Do you get an error? Then post the full error.
    If you get unexpected behviour then explain what happens and what should happen instead.

    One = is assingment. Two = is comparison. You do not need the if statement anyway. If you get the index from one combobox use it to set the index of the other combobox.

  8. #8
    nksjolinder1 is offline Member
    Join Date
    Oct 2011
    Posts
    9
    Rep Power
    0

    Default Re: Combo Boxes HELP

    please bear with me i am just a little confused. how could i go about this without an if statement?

  9. #9
    Junky's Avatar
    Junky is offline Grand Poobah
    Join Date
    Jan 2011
    Location
    Dystopia
    Posts
    3,789
    Rep Power
    7

    Default Re: Combo Boxes HELP

    If you have the options of the two boxes in parallel then their indicies will be the same: blue = 0, blueberry = 0, red = 1, strawberry = 1 etc.

Similar Threads

  1. Replies: 12
    Last Post: 05-04-2011, 09:31 PM
  2. Replies: 0
    Last Post: 04-27-2011, 10:34 AM
  3. Comparing two combo boxes
    By Wednesday Bass in forum AWT / Swing
    Replies: 2
    Last Post: 03-27-2011, 12:28 PM
  4. multiple combo boxes
    By simo_mon in forum AWT / Swing
    Replies: 1
    Last Post: 07-22-2010, 11:57 AM
  5. [SOLVED] Combo Boxes Automation
    By dbashby in forum New To Java
    Replies: 3
    Last Post: 03-27-2009, 12:39 AM

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
  •