| Author |
Internationalization of TreeMap
|
Isaac Hewitt
Ranch Hand
Joined: Jul 24, 2006
Posts: 179
|
|
Hi everyone,
I have the contents of a <String, Bean>TreeMap displayed in a JTable. The leftmost column displays film titles (the String part of the TreeMap), mostly in English, but some in foreign languages such as French. The titles are in alphabetical order alright except if the title contains an accent such as the one in the French word hotel where it falls on the "o". I will try to type the word with the accent not knowing if it will show up on your computer screen, here goes: "hôtel". In this case the French word hotel with the accent ends up almost at the end of the column. I would like to have the titles in alphabetical order regardless of foreign accents, hence only taking into account ordinary spelling. Is there a way to make my JTable or TreeMap international? Thanks.
|
 |
John de Michele
Rancher
Joined: Mar 09, 2009
Posts: 600
|
|
Isaac,
Sorting for String is in asciibetacal order. Since the codes for accented characters follow after all of the non-accented characters, they fall to the bottom. You should look into the java.text.Collator class and its subclass RuleBasedCollator.
John.
|
 |
Rob Spoor
Sheriff
Joined: Oct 27, 2005
Posts: 19216
|
|
|
And fortunately, Collator implements Comparator<Object> so you can use one in the TreeMap constructor.
|
SCJP 1.4 - SCJP 6 - SCWCD 5
How To Ask Questions How To Answer Questions
|
 |
 |
|
|
subject: Internationalization of TreeMap
|
|
|