Created
September 21, 2015 23:41
-
-
Save anonymous/d94752f3c64ceaf1c4ea to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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