This week's book giveaway is in the Agile and Other Processes forum.
We're giving away four copies of The Little Book of Impediments (e-book only) and have Tom Perry on-line!
See this thread for details.
Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Loading Values into JComboBox, depending on selection from another JComboBox?

 
md nayeem
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Loading Values into JComboBox, depending on selection from another JComboBox?
if i hava a jcombobox value with Division likeDhaka,Rajshahi,Rangpur.then i want to load another combobox ciity values like Motijheel,Mirpur,Rajbari .if i select Dhaka from the first jcombobox then automatically the city Motijheel will be selected in the second jcombobox.I need detail explaination about this kind of programming.I am now learning java programming from Scratch.
Untitled.png
[Thumbnail for Untitled.png]
 
Maneesh Godbole
Saloon Keeper
Posts: 11327
16
Android Eclipse IDE Google Web Toolkit Java Mac Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to the Ranch

What you need is to listen to the selection change in division combo box and (re)populate your city combo accordingly.
Using an ActionListener should do the trick.
Check out https://docs.oracle.com/javase/tutorial/uiswing/components/combobox.html#listeners for sample code.
 
Rob Camick
Ranch Hand
Posts: 2673
9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
For example:


Note this example uses the JComboBox.isTableCellEditor property so ActionEvents are not generated when the up/down arrows are used on the combo box. The ActionEvent is only generated when the item is actually selected.
 
Knute Snortum
Bartender
Pie
Posts: 2897
62
Chrome Eclipse IDE Java Postgres Database VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Do you have a jar for SwingUtils?
 
Rob Camick
Ranch Hand
Posts: 2673
9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Oops. Sorry, that part of the code is not required for this solution. In the past I was testing something else and forgot to remove it. By the way the SwingUtils code doesn't work in this example although it can be helpful in many other situations.

I'll comment out the code but leave it here in case you are interested in its functionality.

I don't have a jar but I have created a blog for some of my tips/ideas. So you can check out Swing Utils
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic