Collator.getInstance(new Locale("sv", "")) : Collator « I18N « Java






Collator.getInstance(new Locale("sv", ""))

  

import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.text.Collator;
import java.util.Collections;
import java.util.Locale;
import java.util.Vector;

import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;

public class SortAndPain extends JPanel {
  public SortAndPain() {
    Vector list = new Vector();
    list.add("\u00e4pple");
    list.add("apple");
    list.add("p\u00e4ron");
    list.add("orange");

    Collator collate = Collator.getInstance(new Locale("sv", ""));
    Collections.sort(list, collate);

    for (int i = 0; i < list.size(); i++) {
      add(new JLabel(list.elementAt(i));
    }
  }

  public static void main(String s[]) {
    SortAndPain panel = new SortAndPain();
    JFrame frame = new JFrame("Sort");
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frame.getContentPane().add("Center", panel);
    frame.pack();
    frame.setVisible(true);
  }
}

   
  








Related examples in the same category

1.Comparing Half-Width and full-width A
2.Collator.NO_DECOMPOSITION
3.Collator.CANONICAL_DECOMPOSITION
4.Collator.FULL_DECOMPOSITION
5.Sort Collate
6.I18N SortI18N Sort
7.Searching, Sorting, and Text Boundary Detection: Collation IssuesSearching, Sorting, and Text Boundary Detection: Collation Issues
8.Compare accentuated letters
9.Check Equality for two strings with Collator
10.Sort strings using Collator class
11.I18N : TextI18N : Text