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