I make 3 comboboxes which relate to each other. If I choose "a" for the first comboBox, the the second comboBox should be "b" (no other options) and the same way for the third combo box.
The problem is, it always said that "Cannot invoke "Object.toString()" because the return value of "javax.swing.JComboBox.getSelectedItem()" is null"
here is my code for the first comboBox:
private void dimensiComboBoxActionPerformed(java.awt.event.ActionEvent evt) {
if("Kepemimpinan".equals(dimensiComboBox.getSelectedItem().toString())){
String jurusan= "Kepemimpinan";
if(kategoriComboBox.getSelectedItem()!=null)
kategoriComboBox.removeAllItems();
//if(egoriComboBox.removeAllItems();null ==kategoriComboBox)
isiMatkul(jurusan);
//kategoriComboBox.addItem("Kategori");
System.out.println(kategoriComboBox.getSelectedIndex());
}//else{matkulComboBox.removeAllItems();}
else if("Kompetensi Individu".equals(dimensiComboBox.getSelectedItem().toString())){
String jurusan= "Kompetensi Individu";
if(kategoriComboBox.getSelectedItem()!=null) kategoriComboBox.removeAllItems();
System.out.println(kategoriComboBox.getSelectedIndex());
isiMatkul(jurusan);
}//else{matkulComboBox.removeAllItems();}
else if("Jiwa Sosial".equals(dimensiComboBox.getSelectedItem().toString())){
String jurusan= "Jiwa Sosial";
System.out.println(kategoriComboBox.getSelectedIndex());
if(kategoriComboBox.getSelectedItem()!=null)kategoriComboBox.removeAllItems();
isiMatkul(jurusan);
}//else{matkulComboBox.removeAllItems();}
else if("Pengembangan Minat dan Kreativitas".equals(dimensiComboBox.getSelectedItem().toString())){
String jurusan= "Pengembangan Minat dan Kreativitas";
System.out.println(kategoriComboBox.getSelectedIndex());
if(kategoriComboBox.getSelectedItem()!=null)kategoriComboBox.removeAllItems();
isiMatkul(jurusan);
}//else{matkulComboBox.removeAllItems();}
}
the second combo box value depends on the first combobox:
private void kategoriComboBoxActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
if(kategoriComboBox.getSelectedItem()==null){
System.out.println(kategoriComboBox.getSelectedItem().toString());}
else{
if ("Pendidikan".equals(kategoriComboBox.getSelectedItem().toString())) {
String jurusan= "Pendidikan";
subKategoriComboBox.removeAllItems();
//System.out.println(subKategoriComboBox.getSelectedIndex());
isiSubKategori(jurusan);
} //else{matkulComboBox.removeAllItems();}
else if("Ormawa".equals(kategoriComboBox.getSelectedItem().toString())){
String jurusan= "Ormawa";
subKategoriComboBox.removeAllItems();
isiSubKategori(jurusan);
}//else{matkulComboBox.removeAllItems();}
else if("Pelaksana Organisasi".equals(kategoriComboBox.getSelectedItem().toString())){
String jurusan= "Pelaksana Organisasi";
subKategoriComboBox.removeAllItems();
isiSubKategori(jurusan);
}//else{matkulComboBox.removeAllItems();}
else if("Narasumber".equals(kategoriComboBox.getSelectedItem().toString())){
String jurusan= "Narasumber";
subKategoriComboBox.removeAllItems();
isiSubKategori(jurusan);
}//else{matkulComboBox.removeAllItems();}
else if("Prestasi".equals(kategoriComboBox.getSelectedItem().toString())){
String jurusan= "Prestasi";
subKategoriComboBox.removeAllItems();
isiSubKategori(jurusan);
}//else{matkulComboBox.removeAllItems();}
else if("Juara Kompetisi".equals(kategoriComboBox.getSelectedItem().toString())){
String jurusan= "Juara Kompetisi";
subKategoriComboBox.removeAllItems();
isiSubKategori(jurusan);
}//else{matkulComboBox.removeAllItems();}
else if("Peserta Kompetisi".equals(kategoriComboBox.getSelectedItem().toString())){
String jurusan= "Peserta Kompetisi";
subKategoriComboBox.removeAllItems();
isiSubKategori(jurusan);
}//else{matkulComboBox.removeAllItems();}
else if("Olimpiade Perguruan Tinggi Kedinasan".equals(kategoriComboBox.getSelectedItem().toString())){
String jurusan= "Olimpiade Perguruan Tinggi Kedinasan";
subKategoriComboBox.removeAllItems();
isiSubKategori(jurusan);
}//else{matkulComboBox.removeAllItems();}
else if("Kompetisi Internal STIS".equals(kategoriComboBox.getSelectedItem().toString())){
String jurusan= "Kompetisi Internal STIS";
subKategoriComboBox.removeAllItems();
isiSubKategori(jurusan);
}//else{matkulComboBox.removeAllItems();}
else if("Putra-Putri STIS".equals(kategoriComboBox.getSelectedItem().toString())){
String jurusan= "Putra-Putri STIS";
subKategoriComboBox.removeAllItems();
isiSubKategori(jurusan);
}//else{matkulComboBox.removeAllItems();}
else if("Penulis Buku".equals(kategoriComboBox.getSelectedItem().toString())){
String jurusan= "Penulis Buku";
subKategoriComboBox.removeAllItems();
isiSubKategori(jurusan);
}//else{matkulComboBox.removeAllItems();}
else if("Jurnal Ilmiah".equals(kategoriComboBox.getSelectedItem().toString())){
String jurusan= "Jurnal Ilmiah";
subKategoriComboBox.removeAllItems();
isiSubKategori(jurusan);
}//else{matkulComboBox.removeAllItems();}
else if("Menjadi Pembicara/Pelatih".equals(kategoriComboBox.getSelectedItem().toString())){
String jurusan= "Menjadi Pembicara/Pelatih";
subKategoriComboBox.removeAllItems();
isiSubKategori(jurusan);
}//else{matkulComboBox.removeAllItems();}
else if("Panitia Kegiatan Sosial".equals(kategoriComboBox.getSelectedItem().toString())){
String jurusan= "Panitia Kegiatan Sosial";
subKategoriComboBox.removeAllItems();
isiSubKategori(jurusan);
}
else if("Relawan Kegiatan Sosial".equals(kategoriComboBox.getSelectedItem().toString())){
String jurusan= "Relawan Kegiatan Sosial";
subKategoriComboBox.removeAllItems();
isiSubKategori(jurusan);
}
else if("Pelatihan dan Pengabdian Masyarakat".equals(kategoriComboBox.getSelectedItem().toString())){
String jurusan= "Pelatihan dan Pengabdian Masyarakat";
subKategoriComboBox.removeAllItems();
isiSubKategori(jurusan);
}
else if("Kegiatan Sosial Lainnya".equals(kategoriComboBox.getSelectedItem().toString())){
String jurusan= "Kegiatan Sosial Lainnya";
subKategoriComboBox.removeAllItems();
isiSubKategori(jurusan);
}
else if("Peserta Seminar".equals(kategoriComboBox.getSelectedItem().toString())){
String jurusan= "Peserta Seminar";
subKategoriComboBox.removeAllItems();
isiSubKategori(jurusan);
}
else if("Keanggotaan UKM/Bidang/Divisi".equals(kategoriComboBox.getSelectedItem().toString())){
String jurusan= "Keanggotaan UKM/Bidang/Divisi";
subKategoriComboBox.removeAllItems();
isiSubKategori(jurusan);
}
else if("Peserta Kegiatan Terbuka UKM/SEMA".equals(kategoriComboBox.getSelectedItem().toString())){
String jurusan= "Peserta Kegiatan Terbuka UKM/SEMA";
subKategoriComboBox.removeAllItems();
isiSubKategori(jurusan);
}
}
}
this "isiSubKategori(jurusan)" and "isiMatkul(jurusan)" is for filling comboBox with the value user selected.