Hi guys.
I am having issues with a program I am writing.
Basically, I have a JList that stores toString() references of "Location" type objects. I want to be able to remove these.
However, the "Location" type objects are stored in an ArrayList, hence requiring an overriding toString() method to display them correctly in the JList.
Now, I want to be able to remove these refernces from the JList AND remove the corresponding entry from my ArrayList. However, the objects stored in the JList are just toString() representations of them. SO my question is, for my method to remove a selection from my JList, how could I tell the method that I want the actual object removed from the ArrayList as well, not just the String format?
To retrieve the current value selected in the JList, the returned value is of type Object:
Object obj = watchList.getSelectedValue();
I have tried casting this back to a Location type object but this doesn't seem to work. Also, knowing that both toString() methods for Locations and Objects would produce a match, I've also tried comparing String representations of both, ie:
while(it1.hasNext()){
Object obj = watchList.getSelectedValue();
Location loc = it1.next();
String locStr = loc.toString();
if(locStr == obj.toString())
{watchListCollection.remove(loc)}
But this has no effect either. Hope I've made sense. Can anybody possibly help me here?
Thanks!
Than