Basically the question title says it all. I have a column of strings (called type
) in a tableview and a corresponding column of numbers (called size
),
Assuming I understand the question correctly, you need to initialize your cargoList
with an extractor:
ObservableList cargoList = FXCollections.observableArrayList(cargo ->
new Observable[]{cargo.typeProperty(), cargo.sizeProperty()});
ChoiceBox
has a history of not working well with update notifications to its underlying list; I'm not sure if everything is fixed in the latest version. You might want to consider switching to a ComboBox
instead.
Update
If you need to use a ChoiceBox
, a workaround might be not to set the items directly to cargoList
, but to update the items whenever cargoList
changes. You can do this by making the following change in setMainApp(...)
:
// externalChoiceBox.setItems(cargoList);
externalChoiceBox.getItems().setAll(cargoList);
and adding the following in your list change listener:
cargoList.addListener(new ListChangeListener< CargoItem>(){
public void onChanged(Change extends CargoItem> c){
// Do your changes here
System.out.println(c.getList());
externalChoiceBox.getItems().setAll(cargoList);
}});