Win a copy of Cross-Platform Desktop Applications: Using Node, Electron, and NW.js this week in the JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Problem with JCombo Boxes  RSS feed

 
VenuArchana Aradhyula
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have two JCombo boxes
For eg comb1 and cmb2.
In cmb1 i will store two items like fruits,vegetables.
In cmb2 i have to store the items like names of fruits and names of vegetables.

Now when i select fruits in cmb1 i must get the names of furits like applie,banana,grapes etc in cmb2.
Now when i select vegetables in cmb1 i must get the name of vegetables like brinjal,cucumber,etc in cmb2.

I think i have to implement focus listeners for the combo box.
But iam not able to get it.

Thanks
Archana
 
Pavan Kumar Srinivasan
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Combo Actions will have to work with

1) ActionListeners --> which are fired everytime the user makes a selection
2)ItemSelectionListener --> which will be fired twice ,once for unselection ,other for selection.


http://java.sun.com/docs/books/tutorial/uiswing/components/combobox.html
should give more info abt combo-boxes.

In your case , the model in combo2 has to be filtered based on the item selection in combo1
[ October 16, 2008: Message edited by: Pavan Kumar Srinivasan ]
 
Rob Spoor
Sheriff
Posts: 21044
85
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Not focus listener but action listener.

If the selection of combo 1 changes, you want to catch that event and change the contents of combo 1. In pseudo code:

If you are confused about how I created that ActionListener, search on anonymous classes.
 
Maneesh Godbole
Bartender
Posts: 11445
18
Android Eclipse IDE Google Web Toolkit Java Mac Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Let us call your combo1 the parent and combo2 the child.
When the selection in parent changes, the data in child needs to be changed.

Usually you can get notified of the parent changes via an ActionListener.
You can change the child data by calling the setModel().

It might also be a good idea to check this out
http://java.sun.com/docs/books/tutorial/uiswing/components/combobox.html

OK. I see Pavan and Rob have already beaten me to it
[ October 16, 2008: Message edited by: Maneesh Godbole ]
 
VenuArchana Aradhyula
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for your advice. I got the solution now.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!