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 类显示国家/地区列表。但是,当我运行代码时,我只能在组合框中显示一个国家/地区。我不确定是我循环错误还是什么。
最佳答案
使用此代码
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);
}
关于java - 如何在 ComboBox 中显示所有国家/地区列表? [JavaFX],我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43674408/