如何在ComboBox中显示所有国家/地区列表? [JavaFX] [英] How do I display all country list in ComboBox? [JavaFX]

查看:76
本文介绍了如何在ComboBox中显示所有国家/地区列表? [JavaFX]的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

public void start(final Stage frame) throws Exception {
    String[] locales = Locale.getISOCountries();
    for (String countrylist : locales) {
        Locale obj = new Locale("", countrylist);
        String[] city = {obj.getDisplayCountry()};
        for (int x = 0; x < city.length; x++) {
            cities = FXCollections.observableArrayList(obj.getDisplayCountry());
            country = new ComboBox<String>(cities);
        }
    }
}

我想使用Locale类显示国家列表.但是,当我运行代码时,我只能在组合框中显示一个国家.我不确定是否弄错了循环还是什么.

I want to display the country list using Locale class. However I only manage to display one country in the Combobox when I run the code. I am not sure whether I got the loop wrong or what.

推荐答案

使用此代码

  public void start(Stage primaryStage) throws Exception {

                ObservableList<String> cities = FXCollections.observableArrayList();
                ComboBox<String> country = new ComboBox<String>(cities);

                String[] locales1 = Locale.getISOCountries();
                for (String countrylist : locales1) {
                    Locale obj = new Locale("", countrylist);
                    String[] city = { obj.getDisplayCountry() };
                    for (int x = 0; x < city.length; x++) {
                        cities.add(obj.getDisplayCountry());
                    }
                }
                country.setItems(cities);
 }

这篇关于如何在ComboBox中显示所有国家/地区列表? [JavaFX]的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆