I have the following method to add objects to a JComboBox
:
public void PopulaCategoria() throws SQLException{
for(Categoria categoria : caDAO.getCategorias()){
comboCategoria.addItem(categoria);
}
}
But the error in comboCategoria.addItem(categoria);
saying that Categoria
can not be converted to String
, however I already put toString()
method inside my Categoria
model:
@Override
public String toString(){
return this.nomCategoria;
}
Should not it add objects within JComboBox
and show only the name?