Reputation: 194
One list:
ListView list = (ListView) pane.lookup("#list");
ObservableList<String> countries = FXCollections.observableArrayList(
"England", "Germany", "France", "Israel");
list.setItems(countries);
Please tell me how to do like this?
ListView list = (ListView) root.lookup("#list");
ObservableList<String> countries = FXCollections.observableArrayList(
"England", "Germany", "France", "Israel");
ObservableList<String> capitals = FXCollections.observableArrayList(
"London", "Berlin", "Paris", "Ierusalim");
Upvotes: 1
Views: 916
Reputation: 5032
There is an example for you. Just make a bean with country and capital field. And you will have a ListView of YourBean. Like that :
The bean
public class MyBean {
private String country;
private String capital;
public MyBean(String country, String capital) {
this.country = country;
this.capital = capital;
}
public String getCountry() {
return country;
}
public void setCountry(String country) {
this.country = country;
}
public String getCapital() {
return capital;
}
public void setCapital(String capital) {
this.capital = capital;
}
}
and the ListView
public class Example extends ListView<MyBean> {
public Example() {
this.getItems().add(new MyBean("France", "Paris"));
this.getItems().add(new MyBean("England", "London"));
this.setCellFactory(new Callback<ListView<MyBean>, ListCell<MyBean>>() {
@Override
public ListCell<MyBean> call(ListView<MyBean> myBeanListView) {
return new ListCell<MyBean>() {
@Override
protected void updateItem(MyBean myBean, boolean b) {
super.updateItem(myBean, b);
if (!b) {
HBox box = new HBox();
box.setSpacing(50);
box.getChildren().add(new Label(myBean.getCountry()));
box.getChildren().add(new Label(myBean.getCapital()));
setGraphic(box);
} else {
setGraphic(null);
}
}
};
}
});
}
}
You just have to adapt it to your program but it for show you the good setCellFactory method
Upvotes: 1