Forums Register Login

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

+Pie Number of slices to send: Send
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
[Untitled.png]
+Pie Number of slices to send: Send
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.
+Pie Number of slices to send: Send
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.
+Pie Number of slices to send: Send
Do you have a jar for SwingUtils?
+Pie Number of slices to send: Send
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
A wop bop a lu bop a womp bam boom! Tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com


reply
reply
This thread has been viewed 2331 times.
Similar Threads
Jsp
Loading Values into JComboBox, depending on selection from another JComboBox
Comboboxes in a jsp page.
About JComboBox and JRadioButton
Jtable combo box issue
More...

All times above are in ranch (not your local) time.
The current ranch time is
Mar 28, 2024 08:49:19.