• Post Reply Bookmark Topic Watch Topic
  • New Topic

populate JComboBox at run time problem

 
Vikas Kumar Sahu
Ranch Hand
Posts: 59
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Java Gurus,
Please understand my problem.
I m making a gui of simple userregistration using swing.
I have 2 jcombo box one for countries and other is for city.
what i want my city combo should populte only cities of selected country.
So How can i do that.
I m doing something this and city combo has country specific
names but what happened , it is not reflecting in gui.
because i want run time selection of country combo and city combo should populate
like that way that i describe before.
private void populateData(ActionEvent e){
Vector tempVector = new Vector();
System.out.println("before filtering size of cityVector =" + tempVector.size());
JComboBox cb = (JComboBox)e.getSource();
Object newItem = cb.getSelectedItem();
int country_id = ((CountryNames)newItem).getCountryId();
for(int i=0; i< allCityVector.size(); i++){
CityNames cityNames = (CityNames)allCityVector.get(i);
if(cityNames.getCountryID() == country_id){
tempVector.add(cityNames);
}
}
Collections.sort(tempVector, new CityNamesSorter(true));
cityCmb.removeAll();
cityCmb = new JComboBox(tempVector);
cityCmb.updateUI();
System.out.println("after filtering size of cityVector =" + tempVector.size());
}
You can see that cityCmb has new data but it is not reflecting in gui.
Please give me any suggestion.
Thanks in advance.
Regards -
vikas
:roll:
 
Michael Dunn
Ranch Hand
Posts: 4632
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I posted this the other day (somewhere) - but can't find the link
 
Vikas Kumar Sahu
Ranch Hand
Posts: 59
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanx.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!