I'm creating a frame that contains 3 combobox each one is dependent to the other , the 3rd dependent to 2nd and the 2nd is dependent to 1st . The problem is when i change the first i get NullPointer exception on the 3rd because it's actions the change action for the 2nd .
My question is how to prevent the action of item change on the 3rd jComboBox "jCombobox2" when i change the 1st jComboBox "jComboBox0" ?
Here is my code :
private void jComboBox0ItemItemStateChanged(ItemEvent event) {
jComboBox1.removeAllItems();
ComboItem cat = (ComboItem) jComboBox0.getSelectedItem();
String requete = "from Subcategory where Fk_Category = " + cat.getValue();
Collection subcategories = Subcategory.getListeSubcategory(requete);
for (Iterator i = subcategories.iterator(); i.hasNext();) {
Subcategory item = new Subcategory();
item = (Subcategory) i.next();
System.out.println(item.getId());
jComboBox1.addItem(new ComboItem(item.getNom(), (int) item.getId()));
}
// System.out.println("tbdlat a lkhra ! : "+listCategory.get(0));
}
private void jComboBox1ItemItemStateChanged(ItemEvent event) {
// nda2
jComboBox2.removeAllItems();
ComboItem cat = (ComboItem) jComboBox1.getSelectedItem();
String requete = "from Area where fk_Subcategory = " + cat.getValue()+" group by Nom_Area";
Collection areas = Area.getListeArea(requete);
for (Iterator i = areas.iterator(); i.hasNext();) {
Area item = new Area();
item = (Area) i.next();
System.out.println(item.getId());
jComboBox2.addItem(new ComboItem(item.getNom(), (int) item.getId()));
}
}
private void jComboBox2ItemItemStateChanged(ItemEvent event) {
// i'll do some code here
}