pb appel méthode classe mère, StackOverflowError
Bonjour à tous,
voici mon code :
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
| public class MyJCombobox extends JComboBox{
public MyJCombobox() {
super();
}
@Override
public void addItem(Object anObject){
ArrayList<String> array = new ArrayList<String>(this.getItemCount() + 1);
for (int i = 0; i < this.getItemCount(); i++)
array.add((String)this.getItemAt(i));
array.add((String)anObject);
Collections.sort(array);
this.removeAllItems();
for (int i = 0; i < array.size(); i++)
((JComboBox)this).addItem(array.get(i));
}
} |
j'ai donc juste defini une classe heritant de JComboBox, pour y redefinir la methode addItem, pour qu'elle ajoute un item mais en rangeant dans l'ordre alphabetique. Mais qd j'appelle cette fonction, j'ai une erreur : StachOverflowError.
pourtant le addItem de ma classe fille appelle bien le addItem de la classe mère (j'ai fait un cast), alors je comprend pas.
Merci à vous pour vos idées