Java jList add item based on combobox selection
Posted
by
Stephan Badert
on Stack Overflow
See other posts from Stack Overflow
or by Stephan Badert
Published on 2012-06-20T20:45:42Z
Indexed on
2012/06/20
21:16 UTC
Read the original article
Hit count: 178
I have a csv file that is being loaded in my programme. It contains citys and areas and some other stuff (not important here). Once the csv is selected I load the data into several comboboxes.
1 Thing is not working, I have a combobox containing all the citys and now I need to list all the areas for that country based on selection from the combobox.
Here is the event:
private void cboProvinciesItemStateChanged(java.awt.event.ItemEvent evt) {
//System.out.println(Arrays.asList(gemeentesPerProvincie(gemeentes)));
invullenListProvincie(gemeentes);
}
Here is the method:
private void invullenListProvincie(ArrayList<Gemeentes> gemeentes) {
Gemeentes gf = (Gemeentes) cboProvincies.getSelectedItem();
DefaultListModel model = new DefaultListModel();
JList list = new JList(model);
for (Gemeentes gemeente : gemeentesPerProvincie(gemeentes)) {
model.addElement(gemeente);
}
lstGemeentes.setModel(model);
}
and this is the method to filter all the areas that equal the selection from the combobox:
private ArrayList<Gemeentes> gemeentesPerProvincie(ArrayList<Gemeentes> gemeentes) {
String GemPerProv = (String) cboProvincies.getSelectedItem();
ArrayList<Gemeentes> selectie = new ArrayList<Gemeentes>();
for (Gemeentes gemeente : gemeentes) {
if (gemeente.getsProvincie().equals(GemPerProv)) {
selectie.add(gemeente);
}
}
return selectie;
}
I am convinced the error is the way I am trying to add items to the jList gemeentesPerProvincie(), I have tried so many things already. I really hope someone can see what i am clearly missing...
© Stack Overflow or respective owner