I want to find out how to Dynamically add Contents to a JComboBox with values from the database based on ItemEvents from another JComboBox. For instance i have 2 ComboBoxes called phoneBrand and phoneModels. Am trying to change the content of phoneModel based on a selection from the phoneBrand ComboBox. Like; I want the phoneModel ComboBox to display Nokia E6, Nokia X7, etc if the phoneBrand's selection is Nokia.
Asked
Active
Viewed 471 times
-1
-
[What have you tried?](http://www.whathaveyoutried.com/) I mean *besides* asking us. – Andrew Thompson Oct 20 '13 at 09:08
-
This will help you : http://stackoverflow.com/questions/10367834/how-to-control-a-combo-box-by-using-another-combo-box-swing – Alexis C. Oct 20 '13 at 09:08
-
I voted to close this on the grounds that it does not demonstrate a minimal understanding of the problem. But it could just as easily be closed as a duplicate of many other posts, including [this one](http://stackoverflow.com/q/19172677/418556). – Andrew Thompson Oct 20 '13 at 09:12
-
voting to close - it's **invredible** that you obviously didn't do **anything** to try and solve your problem before coming here. There are tons of tutorials/textbooks/javadoc/examples around, just pick what suits you, try to adjust to your specific problem. Only **after** being stuck at a **concrete** point, ask here - with a SSCCE that reproduces the problem and shows your efforts. – kleopatra Oct 20 '13 at 10:09
1 Answers
1
The simplest way is to simple change the combo boxes model.
The idea would be to attach an ActionListener
to the first combo box, when it's actionPerformed
method is triggered, you would load the values you need from the database into a new ComboBoxModel
and apply it to the second combo box.
Take a look at

MadProgrammer
- 343,457
- 22
- 230
- 366
-
3What a co-incidence! After voting to close, I realized this qn. was also a duplicate, and on the first dup. I found that had an accepted answer, the answer was by you. ;) – Andrew Thompson Oct 20 '13 at 09:15
-
2@AndrewThompson That sounds about right, repeat, repeat, repeat...story of my life :P – MadProgrammer Oct 20 '13 at 09:33
-
2@AndrewThompson yeah, nowadays the OPs seem to rarely read *anything*, neither tutorials nor examples nor other questions nor ..., – kleopatra Oct 20 '13 at 10:04
-
2@kleopatra I almost thought that was going to end, *"..nor [TFM](http://stackoverflow.com/a/19469472/418556).."* ;) – Andrew Thompson Oct 20 '13 at 10:09
-
@MadProgrammer I'll make sure i read more on your suggestions, I appreciate! – aknessy Oct 20 '13 at 10:12
-
@AndrewThompson: It's really bad for a guy to jump into conclusions about others, especially when you don't have any clue about who they are or what efforts they are making on their own. This is my first time here, I'd have posted the codes if i knew how! Most forums make use of certain mark-ups or mark-downs as the case may be. I tried to prevent a copy'n'paste situation! So next time, please be rational! Thanks though! – aknessy Oct 20 '13 at 10:16
-
2@IsaacNessy Next time, please read the forum for a few days to get an idea how it works, rather than launch in with an ill-formed question, expecting others to fix it for you/be psychic about what you mean. – Andrew Thompson Oct 20 '13 at 10:19
-
-
@IsaacNessy there is **absolutely no way** around reading up on some basics before asking questions here (and anywhere else) - and be it only for understanding the answers. – kleopatra Oct 20 '13 at 10:25