• Post Reply Bookmark Topic Watch Topic
  • New Topic

Internationalization of TreeMap  RSS feed

 
Isaac Hewitt
Ranch Hand
Posts: 191
Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 600
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 21135
87
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
And fortunately, Collator implements Comparator<Object> so you can use one in the TreeMap constructor.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!