Problem with setSelectedValue Method for JList?

The problem you are describing usually means that the object wasn't found in the list. The setSelectedValue() method works doing calls to object.equals() (in your case String.equals() ), so the probable cause is that the strings contained in aux are capitalized in a different way than the string you are trying to select For instace aux may contain the string "alumnos" instead of "Alumnos". There are two alternatives for this, if you don't care about capitalization (then change the string "Alumnos" to whatever is inside aux ) if you do care about the capitalization and you still want to use strings, you could simple create a MyString class that extends String and overrides the equals method, something like: public class MyString extends String { @Override public boolean equals(Object obj){ if (obj instanceof String){ String obj2 = (String)obj; return this.

EqualsIgnoreCase(obj2); } return false; } } Another alternative (perhaps a nicer one) is to create a wrapper object for your list public class MyWrapper { private String payload; public MyWrapper(String payload){ this. Payload = payload; } @Override public String toString(){ return payload; } @Override public boolean equals(Object obj){ if (obj instanceof MyWrapper){ MyWrapper obj2 = (MyWrapper)obj; return payload. EqualsIgnoreCase(obj2.

Payload); } return false; } }.

The problem you are describing usually means that the object wasn't found in the list. The setSelectedValue() method works doing calls to object.equals() (in your case String.equals()), so the probable cause is that the strings contained in aux are capitalized in a different way than the string you are trying to select. For instace aux may contain the string "alumnos" instead of "Alumnos".

There are two alternatives for this, if you don't care about capitalization (then change the string "Alumnos" to whatever is inside aux) if you do care about the capitalization and you still want to use strings, you could simple create a MyString class that extends String and overrides the equals method, something like: public class MyString extends String { @Override public boolean equals(Object obj){ if (obj instanceof String){ String obj2 = (String)obj; return this. EqualsIgnoreCase(obj2); } return false; } } Another alternative (perhaps a nicer one) is to create a wrapper object for your list. Public class MyWrapper { private String payload; public MyWrapper(String payload){ this.

Payload = payload; } @Override public String toString(){ return payload; } @Override public boolean equals(Object obj){ if (obj instanceof MyWrapper){ MyWrapper obj2 = (MyWrapper)obj; return payload. EqualsIgnoreCase(obj2. Payload); } return false; } }.

The problem you are describing usually means that the object wasn't found in the list. The setSelectedValue() method works doing calls to object.equals() (in your case String.equals()), so the probable cause is that the strings contained in aux are capitalized in a different way than the string you are trying to select. For instace aux may contain the string "alumnos" instead of "Alumnos".

Another alternative (perhaps a nicer one) is to create a wrapper object for your list.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions