evilReiko
evilReiko

Reputation: 20483

Java: Jlist setSelectedValue() but ignoreCase

myJList.setSelectedValue("someTHING", true); //if "SomeThing" in the list, it won't be selected

I want to set the value, but seems like setSelectedValue is case-sensitive, I want to select a value but ignore case-sensitive, is it possible? and how?

Upvotes: 1

Views: 992

Answers (3)

jzd
jzd

Reputation: 23629

setSelectedValue() is not case sensitive, Java is case sensitive.
Two solutions:

  1. Use all upper or lower case in your List
  2. When selecting the value loop through the list and compare the value to the String you want to select using the equalsIgnoreCase() method of String.

Upvotes: 1

Qwerky
Qwerky

Reputation: 18445

Instead of adding String objects to your ListModel you could write your own String wrapper and override the equals(Object o) method to be case insensitive. This might have implications for other areas of your app.

Upvotes: 2

Jigar Joshi
Jigar Joshi

Reputation: 240928

I can't see any one shot method for that but merging one or two method you can have this.

call getNextMatch() until you find the exact element and then setSelectedValue

Upvotes: 1

Related Questions