[英]Add data to Java FX ListView from Map?
I have the following code, and would like to add each "dog" to the ListView. 我有以下代码,并希望将每个“狗”添加到ListView。 The only way I have found to do this so far is by using an ObservableList, but I have been trying this for a long while and still can't get the hang of it. 到目前为止,我发现这样做的唯一方法是使用ObservableList,但是我已经尝试了很长时间了,但仍然无法解决问题。
Does anyone know how I could display each "dog" from the Map, in a JavaFX Listview? 有谁知道我如何在JavaFX Listview中显示地图上的每个“狗”?
Document doc = Jsoup.connect(
"http://www.sportinglife.com/greyhounds/abc-guide").get();
Element tableHeader = doc.select("tbody").first();
Map<String, String> data = new HashMap<>();
for (Element element : tableHeader.children()) {
// Here you can do something with each element
if (element.text().indexOf("Pelaw Grange") > 0
|| element.text().indexOf("Shawfield") > 0
|| element.text().indexOf("Shelbourne Park") > 0
|| element.text().indexOf("Harolds Cross") > 0) {
// do nothing
} else {
String dog = element.select("td:eq(0)").text();
String race = element.select("td:eq(1)").text();
data.put(dog, race);
}
It looks like you are trying to add all the keys from the Map
to your ListView
. 似乎您正在尝试将Map
所有键添加到ListView
。 You can do 你可以做
ListView<String> myListView = new ListView<>();
// ...
myListView.getItems().addAll(data.keySet());
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.