I use this method to fill the comboBoox regarding the student selection so with this I show the subjects that are part of the student's career.
public void listarMaterias(){
ArrayList <Materia> lista = pli.getFacuIng().getListaMaterias();
for (Iterator<Materia> iterator = lista.iterator(); iterator.hasNext();) {
Materia next = iterator.next();
if(carreraPosF.equals(next.getCarrePertenece())){
comboBoxm1.getItems().add(next.getNombreMateria());
comboBoxm2.getItems().add(next.getNombreMateria());
comboBoxm3.getItems().add(next.getNombreMateria());
comboBoxm4.getItems().add(next.getNombreMateria());
comboBoxm5.getItems().add(next.getNombreMateria());
comboBoxm6.getItems().add(next.getNombreMateria());
// System.out.println("Holaaaaaa"+next.getNombre());
}
}
}
Should I do another method or could I take advantage of the same one to clean the comboBox? It's already left, they are always saved with respect to the first student I select.
In the method that fills the
ComboBox
, before the loopfor
, you can add a statement that leaves thecomboBox
, like this:So when you call the method
listarMaterias()
, it will first remove all the data inside theComboBox
, and fill it in again.