BaseGridData implements GridData { protected boolean internalRefreshWidth(boolean changedNumberOfColumn, OptionalDouble optionalCurrentWidth) { double visibleWidth = getVisibleWidth(); if (visibleWidth == 0) { return false; } if (!changedNumberOfColumn && previousVisibleWidth != 0 && visibleWidth == previousVisibleWidth) { return false; } GridWidthMetadata gridWidthMetadata = new GridWidthMetadata(optionalCurrentWidth); if (gridWidthMetadata.numberOfAutoColumn == 0) { return false; } boolean wasFullWidth = Math.abs(gridWidthMetadata.currentGrossWidth - previousVisibleWidth) < 0.1; double targetGrossWidth = wasFullWidth ? visibleWidth : Math.max(visibleWidth, gridWidthMetadata.currentGrossWidth); double currentWidth = getWidth() - gridWidthMetadata.fixedWidth; double targetWidth = targetGrossWidth - gridWidthMetadata.fixedWidth; if (visibleWidth < gridWidthMetadata.currentGrossWidth && !wasFullWidth) { return false; } boolean toRedraw = false; for (GridColumn<?> column : getColumns()) { if (!column.isVisible() || !GridColumn.ColumnWidthMode.isAuto(column)) { continue; } double oldWidth = column.getWidth(); double ratio = oldWidth / currentWidth; double newWidth = ratio * targetWidth; if (oldWidth == 0) { newWidth = calculateInitWidth(column, OptionalDouble.empty()); } if (newWidth < column.getMinimumWidth()) { newWidth = column.getMinimumWidth(); } if (newWidth != oldWidth) { column.setWidth(newWidth); toRedraw = true; } } return toRedraw; } BaseGridData();  BaseGridData(final boolean isMerged); @Override List<GridColumn<?>> getColumns(); @Override int getColumnCount(); @Override void appendColumn(final GridColumn<?> column); @Override void insertColumn(final int index,
                             final GridColumn<?> column); @Override void deleteColumn(final GridColumn<?> column); @Override void moveColumnTo(final int index,
                             final GridColumn<?> column); @Override void moveColumnsTo(final int index,
                              final List<GridColumn<?>> columns); @Override List<GridRow> getRows(); @Override GridRow getRow(final int rowIndex); @Override void appendRow(final GridRow row); @Override void insertRow(final int rowIndex,
                          final GridRow row); @Override Range deleteRow(final int rowIndex); @Override void moveRowTo(final int index,
                          final GridRow row); @Override void moveRowsTo(final int index,
                           final List<GridRow> rows); @Override int getRowCount(); @Override int getHeaderRowCount(); @Override void setHeaderRowCount(final int headerRowCount); @Override GridCell<?> getCell(final int rowIndex,
                               final int columnIndex); @Override SelectedCell getSelectedCellsOrigin(); @Override List<SelectedCell> getSelectedCells(); @Override List<SelectedCell> getSelectedHeaderCells(); @Override void clearSelections(); @Override void updateColumn(final int index,
                             final GridColumn<?> column); @Override boolean isMerged(); @Override void setMerged(final boolean isMerged); @Override boolean isRowDraggingEnabled(); @Override void setRowDraggingEnabled(final boolean enabled); @Override boolean isColumnDraggingEnabled(); @Override void setColumnDraggingEnabled(final boolean enabled); @Override Range setCell(final int rowIndex,
                         final int columnIndex,
                         final Supplier<GridCell<?>> cellSupplier); @Override @SuppressWarnings("unchecked") Range setCellValue(final int rowIndex,
                              final int columnIndex,
                              final GridCellValue<?> value); @Override Range deleteCell(final int rowIndex,
                            final int columnIndex); @Override Range selectCell(final int rowIndex,
                            final int columnIndex); @Override Range selectCells(final int rowIndex,
                             final int columnIndex,
                             final int width,
                             final int height); @Override Range selectHeaderCell(final int headerRowIndex,
                                  final int headerColumnIndex); @Override void collapseCell(final int rowIndex,
                             final int columnIndex); @Override void expandCell(final int rowIndex,
                           final int columnIndex); @Override boolean refreshWidth(); @Override boolean refreshWidth(double currentWidth); @Override boolean setVisibleSizeAndRefresh(int width, int height); @Override int getVisibleWidth(); @Override int getVisibleHeight();  }
@Test public void internalRefreshWidth() { int visibleWidth = 0; double minimumWidth = 600; BaseGridData data = spy(baseGridData); data.setVisibleSizeAndRefresh(visibleWidth, 0); assertFalse(data.internalRefreshWidth(true, OptionalDouble.empty())); visibleWidth = 1000; data.setVisibleSizeAndRefresh(visibleWidth, 0); assertFalse(data.internalRefreshWidth(false, OptionalDouble.empty())); data.setVisibleSizeAndRefresh(visibleWidth, 0); assertFalse(data.internalRefreshWidth(true, OptionalDouble.empty())); visibleWidth = 500; data.setVisibleSizeAndRefresh(visibleWidth, 0); assertFalse(data.internalRefreshWidth(true, OptionalDouble.empty())); BaseGridColumn<String> column = new BaseGridColumn<>(header, columnRenderer, 100.0); data.appendColumn(column); column.setColumnWidthMode(GridColumn.ColumnWidthMode.AUTO); column.setWidth(0); assertTrue(data.internalRefreshWidth(true, OptionalDouble.empty())); assertEquals(visibleWidth, column.getWidth(), 0.1); column.setWidth(0); column.setMinimumWidth(minimumWidth); assertTrue(data.internalRefreshWidth(true, OptionalDouble.empty())); assertEquals(minimumWidth, column.getWidth(), 0.1); BaseGridColumn<String> fixedColumn = new BaseGridColumn<>(header, columnRenderer, 100); data.appendColumn(fixedColumn); column.setWidth(100.0); column.setMinimumWidth(100.0); assertTrue(data.internalRefreshWidth(false, OptionalDouble.empty())); assertEquals(visibleWidth - fixedColumn.getWidth(), column.getWidth(), 0.1); assertFalse(data.internalRefreshWidth(false, OptionalDouble.empty())); assertEquals(visibleWidth - fixedColumn.getWidth(), column.getWidth(), 0.1); }