• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Jeanne Boyarsky
  • Devaka Cooray
  • Paul Clapham
Sheriffs:
  • Tim Cooke
  • Knute Snortum
  • Bear Bibeault
Saloon Keepers:
  • Ron McLeod
  • Tim Moores
  • Stephan van Hulst
  • Piet Souris
  • Ganesh Patekar
Bartenders:
  • Frits Walraven
  • Carey Brown
  • Tim Holloway

populate JComboBox at run time problem

 
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:
 
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.
 
Consider Paul's rocket mass heater.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!