How to populate a TableView that is defined in an fxml file that is designed in JavaFx Scene Builder

后端 未结 2 394
抹茶落季
抹茶落季 2020-12-05 07:36

I would like to know how do I populate a TableView with data... All the examples I have seen creates a TableView with columns and everything and add it to the scene. All don

2条回答
  •  一生所求
    2020-12-05 08:17

    Yo can do this in your controller:

     @FXML
    private TableView table;
    private List users;
    
    @Override
    public void initialize(URL url, ResourceBundle rb) {
        // Set the columns width auto size
        table.getSelectionModel().setSelectionMode(SelectionMode.MULTIPLE);
        table.getColumns().get(0).prefWidthProperty().bind(table.widthProperty().multiply(0.33));    // 33% for id column size
        table.getColumns().get(1).prefWidthProperty().bind(table.widthProperty().multiply(0.33));   // 33% for dt column size
        table.getColumns().get(2).prefWidthProperty().bind(table.widthProperty().multiply(0.33));    // 33% for cv column size
        table.getItems().setAll(this.users);
    }
    

提交回复
热议问题