Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 3 of 3

Thread: JComboBox suggestions/help how can i do this?

  1. #1
    Member
    Join Date
    May 2011
    Location
    west palm beach, FL
    Posts
    189
    My Mood
    Tired
    Thanks
    41
    Thanked 11 Times in 10 Posts

    Default JComboBox suggestions/help how can i do this?

    ok im back again lol but i have searched all over and couldnt really find what i wanted to do so i need some suggestions on how i could do this.

    i have 2 jcomboboxes and i want to make it so when the user selects the item they want from the first combo box the second one adjusts to what they selected how could i go about getting this to work?

    Example:

    Combobox1 has choices 1 2 3 4

    Combobox2 waits till users picks

    user picks 3

    combobox2 loads list of items 3


    i made an array for combox1 choices and put it in the combobox so now i just need a way for combox2 to know that a selection has been made and then how i could make combobox2 update according to what the user chose in combox1

    i tried to put in the action event that if user choses 2 then it would make list 2 = another variable but it tells me cannot change string to string[] and then i tried to put it as an object instead but it just puts unwanted stuff in the combobox (some [L]Java stuff)

    everything i tried has given me problems so i thought i would ask here incase someone had a better idea before i kill myself lol thanks as always anything is much appreciated


  2. #2
    Administrator copeg's Avatar
    Join Date
    Oct 2009
    Location
    US
    Posts
    5,320
    Thanks
    181
    Thanked 833 Times in 772 Posts
    Blog Entries
    5

    Default Re: JComboBox suggestions/help how can i do this?

    Add an action listener to the first JComboBox. This is called when a user makes a choice. In the actionPerformed method, clear all items from the second JComboBox (removeAllItems method), then add each of the choice via the addItem method. It seems you tried something like this and it didn't work. We can't give advice specific to what you tried without an SSCCE demonstrating what you tried.

  3. The Following User Says Thank You to copeg For This Useful Post:

    derekxec (August 24th, 2011)

  4. #3
    Member
    Join Date
    May 2011
    Location
    west palm beach, FL
    Posts
    189
    My Mood
    Tired
    Thanks
    41
    Thanked 11 Times in 10 Posts

    Default Re: JComboBox suggestions/help how can i do this?

    edit: that workeddddddd clearing the second combobox then adding them with additem worked perfect thank you very much

    ah i was trying to add the choices to the second combobox via an array and i didnt clear all the items from the second box so maybe that was my problem ill try to do this way you said and see what happens then if it gives me more problems ill post an SSCCE

    i didnt before because i tried a bunch of random stuff and didnt really pay attention to what i was trying only that it wasnt working so i erased it all to start over again lol

    question off topic a little but how do you relax when everything you try doesnt work? this happens to me and i get very frustrated and dont know how to deal with it
    Last edited by derekxec; August 24th, 2011 at 03:35 PM.

Similar Threads

  1. Optimize/Improvements/Suggestions for my code
    By JimmyNeutron in forum What's Wrong With My Code?
    Replies: 1
    Last Post: July 29th, 2011, 02:57 PM
  2. returns all suggestions
    By mario_tim in forum What's Wrong With My Code?
    Replies: 0
    Last Post: March 26th, 2011, 04:51 AM
  3. Suggestions how to do this?
    By aussiemcgr in forum Java Theory & Questions
    Replies: 1
    Last Post: September 2nd, 2010, 12:18 PM