How to check how many locales are supported by my JVM? Is there a开发者_如何学运维 some method to do it or something else?
ThanksYou can check the locales by using Locale.getAvailableLocales();
method.
Code
import java.util.Arrays;
import java.util.Locale;
import javax.swing.table.*;
import javax.swing.*;
class ShowLocales {
public static void main(String[] args) {
SwingUtilities.invokeLater(new Runnable() {
public void run() {
Locale[] locales = Locale.getAvailableLocales();
LocaleTableModel tableModel = new LocaleTableModel(locales);
JTable localeTable = new JTable(tableModel);
localeTable.setAutoCreateRowSorter(true);
JOptionPane.showMessageDialog(
null,
new JScrollPane(localeTable));
}
});
}
}
class LocaleTableModel extends AbstractTableModel {
private Locale[] locales;
LocaleTableModel(Locale[] locales) {
this.locales = locales;
}
public String getColumnName(int column) {
switch (column) {
case 0:
return "Code";
case 1:
return "Language";
case 2:
return "Country";
case 3:
return "Variant";
}
return "";
}
public Object getValueAt(int row, int column) {
switch (column) {
case 0:
return locales[row].toString();
case 1:
return locales[row].getDisplayLanguage();
case 2:
return locales[row].getDisplayCountry();
case 3:
return locales[row].getDisplayVariant();
}
return null;
}
public int getRowCount() {
return locales.length;
}
public int getColumnCount() {
return 4;
}
}
E.G.
See: http://java.sun.com/developer/technicalArticles/J2SE/locale/
What locales does the Java platform support? You can create any locale that you'd like. However, your runtime environment may not fully support the Locale object you create.
If you want to know what Locale objects you can create, the answer is simple: You can create any locale you'd like. The constructors won't complain about non-ISO arguments. However, a more helpful restatement of the question is this: For which locales do the class libraries provide more extensive information? For which locales can the libraries provide collation, time, date, number, and currency information? Also, you might ask what scripts or writing systems your runtime environment supports.
精彩评论