Load currecy locale, code and symbol to JTable : Currency « I18N « Java Tutorial






Load currecy locale, code and symbol to JTable
import java.util.Currency;
import java.util.Locale;

import javax.swing.JFrame;
import javax.swing.JScrollPane;
import javax.swing.JTable;
import javax.swing.table.AbstractTableModel;
import javax.swing.table.TableModel;

public class ShowCurrencies extends JFrame {
  public ShowCurrencies() {
    setDefaultCloseOperation(EXIT_ON_CLOSE);
    final Locale[] locales = Locale.getAvailableLocales();
    TableModel model = new AbstractTableModel() {
      public int getColumnCount() {
        return 3;
      }
      public String getColumnName(int column) {
        if (column == 0)
          return "Locale";
        else if (column == 1)
          return "Currency Code";
        else
          return "Currency Symbol";
      }

      public int getRowCount() {
        return locales.length;
      }

      public Object getValueAt(int row, int col) {
        if (col == 0)
          return locales[row];
        else
          try {
            if (col == 1)
              return Currency.getInstance(locales[row]).getCurrencyCode();
            else
              return Currency.getInstance(locales[row]).getSymbol(locales[row]);
          } catch (IllegalArgumentException iae) {
            return null;
          }
      }
    };

    JTable table = new JTable(model);
    JScrollPane sp = new JScrollPane(table);
    getContentPane().add(sp);
    pack();
    setVisible(true);
  }

  public static void main(String[] args) {
    new ShowCurrencies();
  }
}








13.11.Currency
13.11.1.Load currecy locale, code and symbol to JTableLoad currecy locale, code and symbol to JTable
13.11.2.Create Currency from a Locale and get its symbol and Default Fraction Digits
13.11.3.Getting Currency Symbols for Locale.US
13.11.4.Getting Currency Symbols for Locale.UK
13.11.5.Getting Currency Symbols for Locale.FRANCE
13.11.6.Get currency symbol