Skip to content

Instantly share code, notes, and snippets.

Created Sep 21, 2015
Embed
What would you like to do?
package com.lynden.testjavafxlistview;
import java.net.URL;
import java.util.ArrayList;
import java.util.List;
import java.util.ResourceBundle;
import javafx.beans.property.ListProperty;
import javafx.beans.property.SimpleListProperty;
import javafx.collections.FXCollections;
import javafx.event.ActionEvent;
import javafx.fxml.FXML;
import javafx.fxml.Initializable;
import javafx.scene.control.Button;
import javafx.scene.control.Label;
import javafx.scene.control.ListView;
public class AppController implements Initializable {
@FXML
private Button button;
@FXML
private Label label;
@FXML
private ListView myListView;
protected List<String> asianCurrencyList = new ArrayList<>();
protected List<String> europeanCurrencyList = new ArrayList<>();
protected ListProperty<String> listProperty = new SimpleListProperty<>();
@FXML
private void handleButtonAction(ActionEvent event) {
listProperty.set(FXCollections.observableArrayList(europeanCurrencyList));
}
@Override
public void initialize(URL url, ResourceBundle rb) {
asianCurrencyList.add("CNH");
asianCurrencyList.add("JPY");
asianCurrencyList.add("HKD");
asianCurrencyList.add("KRW");
asianCurrencyList.add("SGD");
europeanCurrencyList.add("EUR");
europeanCurrencyList.add("GBP");
europeanCurrencyList.add("NOK");
europeanCurrencyList.add("SEK");
europeanCurrencyList.add("CHF");
europeanCurrencyList.add("HUF");
myListView.itemsProperty().bind(listProperty);
//This does not work, you can not directly add to a ListProperty
//listProperty.addAll( asianCurrencyList );
listProperty.set(FXCollections.observableArrayList(asianCurrencyList));
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment