-3

I have a problem. I want to make a drop down choice menu with a list of all the countries in the world without having to add each and every country on its own. Is there a way to do this?

I am applying them in a JFrame to make a GUI.

4

1 回答 1

1

如果要开发 Swing 应用程序,请使用以下语句。

 JComboBox box=new JComboBox(getAllCountries());


 public String[] getAllCountries() {
    String[] countries = new String[Locale.getISOCountries().length];
    String[] countryCodes = Locale.getISOCountries();
    for (int i = 0; i < countryCodes.length; i++) {
        Locale obj = new Locale("", countryCodes[i]);
        countries[i] = obj.getDisplayCountry();
    }
    return countries;
 }
于 2013-09-25T12:00:49.673 回答