Example usage for javafx.scene.control TableView editableProperty

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

Introduction

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

Prototype

public final BooleanProperty editableProperty() 

Source Link

Document

Specifies whether this TableView is editable - only if the TableView, the TableColumn (if applicable) and the TableCells within it are both editable will a TableCell be able to go into their editing state.

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();//ww  w.ja  v a 2 s  .c om

    // 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."));
}