return tableColumn.widthProperty();
private void makeHeaderWrappable(TableColumn col) { Label label = new Label(col.getText()); label.setStyle("-fx-padding: 8px;"); label.setWrapText(true); label.setAlignment(Pos.CENTER); label.setTextAlignment(TextAlignment.CENTER); StackPane stack = new StackPane(); stack.getChildren().add(label); stack.prefWidthProperty().bind(col.widthProperty().subtract(5)); label.prefWidthProperty().bind(stack.prefWidthProperty()); col.setGraphic(stack); }
public void autoFitTable(TableView tableView) { // redispatch only if have master column if (masterColumn != null) { double totalColWidth = 0.0; for (final Object column : tableView.getColumns()) { try { final TableColumn tableColumn = (TableColumn) column; if (tableColumn.isVisible()) { if (!tableColumn.equals(masterColumn)) { totalColWidth += tableColumn.widthProperty().get(); } } } catch (final Exception e) { e.printStackTrace(); } } final double remainingwidth = tableView.getWidth() - totalColWidth; if (remainingwidth > 0 && masterColumn != null) { if (remainingwidth < tableView.getWidth()) { masterColumn.prefWidthProperty().set(remainingwidth - 10); } else { masterColumn.minWidthProperty().set(200); } } } }
/** * Creates a totals column from the original bound column. * * @param boundColumn the original column * @return the totals column */ @SuppressWarnings("unchecked") protected TableColumn<S,?> createTotalsColumn(TableColumn<S,?> boundColumn) { TableColumn totalsColumn = new TableColumn<>(); if (isSummable(boundColumn)) { totalsColumn.setCellValueFactory(boundColumn.getCellValueFactory()); totalsColumn.setCellFactory(boundColumn.getCellFactory()); } // sync column widths totalsColumn.prefWidthProperty().bind(boundColumn.widthProperty()); // sync visibility totalsColumn.visibleProperty().bind(boundColumn.visibleProperty()); return totalsColumn; }