Example usage for javafx.scene.control TableView itemsProperty

List of usage examples for javafx.scene.control TableView itemsProperty

Introduction

In this page you can find the example usage for javafx.scene.control TableView itemsProperty.

Prototype

public final ObjectProperty<ObservableList<S>> itemsProperty() 

Source Link

Document

The underlying data model for the TableView.

Usage

From source file:com.ggvaidya.scinames.dataset.DatasetSceneController.java

private void fillTableViewWithDatasetRows(TableView<DatasetRow> tableView) {
    // We need to precalculate.
    ObservableList<DatasetRow> rows = dataset.rowsProperty();

    // Setup table.
    tableView.editableProperty().set(false);

    ObservableList<TableColumn<DatasetRow, ?>> cols = tableView.getColumns();
    cols.clear();//w  w w . j a  va 2 s. com

    // Set up columns.
    TableColumn<DatasetRow, String> colRowName = new TableColumn<>("Name");
    colRowName.setCellValueFactory((TableColumn.CellDataFeatures<DatasetRow, String> features) -> {
        DatasetRow row = features.getValue();
        Set<Name> names = dataset.getNamesInRow(row);

        if (names.isEmpty()) {
            return new ReadOnlyStringWrapper("(None)");
        } else {
            return new ReadOnlyStringWrapper(
                    names.stream().map(n -> n.getFullName()).collect(Collectors.joining("; ")));
        }
    });
    colRowName.setPrefWidth(100.0);
    cols.add(colRowName);

    // Create a column for every column here.
    dataset.getColumns().forEach((DatasetColumn col) -> {
        String colName = col.getName();
        TableColumn<DatasetRow, String> colColumn = new TableColumn<>(colName);
        colColumn.setCellValueFactory((TableColumn.CellDataFeatures<DatasetRow, String> features) -> {
            DatasetRow row = features.getValue();
            String val = row.get(colName);

            return new ReadOnlyStringWrapper(val == null ? "" : val);
        });
        colColumn.setPrefWidth(100.0);
        cols.add(colColumn);
    });

    // Set table items.
    tableView.itemsProperty().set(rows);

    // What if it's empty?
    tableView.setPlaceholder(new Label("No data contained in this dataset."));
}