private void initialize() {
loadPersistenceContext();
List events = getEventsChoiceBox(getPersistenceContext());
ObservableList
Here is another simple implementation from forums.oracle.com
Create a class for key - value
public class KeyValuePair {
private final String key;
private final String value;
public KeyValuePair(String key, String value) {
this.key = key;
this.value = value;
}
public String getKey() { return key; }
public String toString() { return value; }
}
Then create the ChoiceBox as:
ChoiceBox choiceBox = new ChoiceBox();
Fill the elements as;
choiceBox .getItems().add(new KeyValuePair("1", "Active"));
Hint: Retrive key-value pair from you database into an ArrayList and iterate
To retrieve the value:
choiceBox.getValue().getKey(); // returns the "1"
choiceBox.getValue().toString(); // returns the "Active"