dynamically populate ChoiceBox from editable column in TableView

…衆ロ難τιáo~ 提交于 2019-12-02 10:25:33

Assuming I understand the question correctly, you need to initialize your cargoList with an extractor:

ObservableList<CargoItem> 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);
     }});
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!