Example usage for javafx.scene.control TableCell updateTableColumn

List of usage examples for javafx.scene.control TableCell updateTableColumn

Introduction

In this page you can find the example usage for javafx.scene.control TableCell updateTableColumn.

Prototype

public final void updateTableColumn(TableColumn col) 

Source Link

Document

Updates the TableColumn associated with this TableCell.

Usage

From source file:com.panemu.tiwulfx.table.TableControl.java

protected void resizeToFit(TableColumn col, int maxRows) {
    List<?> items = tblView.getItems();
    if (items == null || items.isEmpty()) {
        return;/*  w w w.  j av a 2  s.com*/
    }

    Callback cellFactory = col.getCellFactory();
    if (cellFactory == null) {
        return;
    }

    TableCell cell = (TableCell) cellFactory.call(col);
    if (cell == null) {
        return;
    }

    // set this property to tell the TableCell we want to know its actual
    // preferred width, not the width of the associated TableColumn
    cell.getProperties().put("deferToParentPrefWidth", Boolean.TRUE);

    // determine cell padding
    double padding = 10;
    Node n = cell.getSkin() == null ? null : cell.getSkin().getNode();
    if (n instanceof Region) {
        Region r = (Region) n;
        padding = r.getInsets().getLeft() + r.getInsets().getRight();
    }

    int rows = maxRows == -1 ? items.size() : Math.min(items.size(), maxRows);
    double maxWidth = 0;
    for (int row = 0; row < rows; row++) {
        cell.updateTableColumn(col);
        cell.updateTableView(tblView);
        cell.updateIndex(row);

        if ((cell.getText() != null && !cell.getText().isEmpty()) || cell.getGraphic() != null) {
            getChildren().add(cell);
            cell.impl_processCSS(false);
            maxWidth = Math.max(maxWidth, cell.prefWidth(-1));
            getChildren().remove(cell);
        }
    }

    col.impl_setWidth(maxWidth + padding);
}