Skip to content

Instantly share code, notes, and snippets.

@rkotov93
Created October 5, 2012 11:25
Show Gist options
  • Save rkotov93/3839316 to your computer and use it in GitHub Desktop.
Save rkotov93/3839316 to your computer and use it in GitHub Desktop.
Table Filling
@SuppressWarnings({ "rawtypes", "unchecked" })
private void fillTable(Integer[][] matrix) {
matrixTable.getItems().clear();
matrixTable.getColumns().clear();
ObservableList<ObservableList> data = FXCollections.observableArrayList();
for (int i = 0; i < matrix[0].length; i++) {
final int j = i;
TableColumn tc = new TableColumn(Integer.toString(i+1));
tc.setCellValueFactory(new Callback<CellDataFeatures<ObservableList,String>,ObservableValue<String>>() {
public ObservableValue<String> call(CellDataFeatures<ObservableList, String> param) {
return new SimpleStringProperty(param.getValue().get(j).toString());
}
});
matrixTable.getColumns().addAll(tc);
}
for (int i = 0;i < matrix.length; i++) {
ObservableList<String> row = FXCollections.observableArrayList();
for (int j = 0; j < matrix[0].length; j++) row.add(Integer.toString(matrix[i][j]));
data.add(row);
}
matrixTable.setItems(data);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment