Autoupdating rows in TableView from model

前端 未结 2 757
情歌与酒
情歌与酒 2020-12-01 15:28

I\'ve been looking information about refreshing data into a tableview. I was trying modifying directly the model, but I get a bug. I modify the model, but the table doesn\'t

2条回答
  •  佛祖请我去吃肉
    2020-12-01 15:47

    There is a bug in TableView update (https://javafx-jira.kenai.com/browse/RT-22463). I had similar problem and after some search this is my workaround. I found that if the columns are removed and then re-added the table is updated.

    public static  void refreshTableView(TableView tableView, List> columns, List rows) {        
        tableView.getColumns().clear();
        tableView.getColumns().addAll(columns);
    
        ObservableList list = FXCollections.observableArrayList(rows);
        tableView.setItems(list);
    }
    


    Example of usage:

    refreshTableView(myTableView, Arrays.asList(col1, col2, col3), rows);
    

提交回复
热议问题