Pergunta

I have no idea why it's happening, I'll look at other parts of my code if I need to but I really prefer it to be something else...

let's say I have the following items in my JList

Beer

Mercedes

Coca Cola

and str == "Mercedes", it will remove everything but this item.

why?

for(int i=0;i<listModel.getSize();i++){
        if (listModel.elementAt(i).equals(str))
            listModel.remove(i);
    }
Foi útil?

Solução

You could try that :

listModel.removeElement(str)

And don't forget to check Strings for null values !

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top