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 :D
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.
Re: JComboBox suggestions/help how can i do this?
edit: :D:D:D:D that workeddddddd clearing the second combobox then adding them with additem worked perfect :D 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 :D 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 :(