for (int i = 0; i < columnCount - 1; i++) { Column col = tableModel.getColumn(i); table.getColumnFormatter().setWidth(i, col.getWidth());
getColumnFormatter().resizeColumnGroup(columns, false);
/*************************************** * Returns the width of a certain table column. * * @param nColumn The column index * * @return The column width in pixels */ private int getColumnWidth(int nColumn) { String sHtmlWidth = aColumnHeaders.get(nColumn).getColumnWidth(); int nWidth; if (sHtmlWidth != null) { nWidth = Integer.parseInt(sHtmlWidth.substring(0, sHtmlWidth.length() - 2)); } else { nWidth = aHeaderTable.getColumnFormatter().getElement(nColumn) .getOffsetWidth(); } return nWidth; }
getColumnFormatter().resizeColumnGroup(columns, false);
public int ensureRowsAndCols(int rows, int cols) { if (colSizes.size() < cols) { for (int i = 0; i < cols; i++) { colSizes.add(125); } } if (table.getRowCount() == 0) { addRow(); } while (table.getRowCount() < rows) { addRow(); } for (int r = 0; r < table.getRowCount(); r++) { if (table.getCellCount(r) < cols) { int growthDelta = cols - table.getCellCount(r); for (int c = 0; c < growthDelta; c++) { table.getColumnFormatter().setWidth(c, colSizes.get(c) + "px"); addCell(r, ""); } assert table.getCellCount(r) == cols : "New size is wrong: " + table.getCellCount(r); } } return cols == 0 ? 1 : cols; }
private void updateTableStructure() { int columnCount = tableModel.getColumnCount(); for (int i = 0; i < columnCount; i++) { Column col = tableModel.getColumn(i); header.setWidget(0, i, col.getColumnTitleWidget()); } for (int i = 0; i < columnCount - 1; i++) { Column col = tableModel.getColumn(i); header.getColumnFormatter().setWidth(i, col.getWidth()); } for (int i = 0; i < columnCount; i++) { Column col = tableModel.getColumn(i); header.getCellFormatter().removeStyleName(0, i, selectionStyle.columnAscending()); header.getCellFormatter().removeStyleName(0, i, selectionStyle.columnDescending()); if (col.getSortDirection() == Column.Ascending) { header.getCellFormatter().addStyleName(0, i, selectionStyle.columnAscending()); } else if (col.getSortDirection() == Column.Descending) { header.getCellFormatter().addStyleName(0, i, selectionStyle.columnDescending()); } } }
/*************************************** * Sets the widths of the table columns. */ void setAllColumnWidths() { ColumnFormatter rHeaderColumnFormatter = aHeaderTable.getColumnFormatter(); ColumnFormatter rDataColumnFormatter = rTable.getDataTable().getColumnFormatter(); int nColumns = rColumns.getElementCount(); for (int nCol = 0; nCol < nColumns; nCol++) { String sColumnWidth = aColumnHeaders.get(nCol).getColumnWidth(); if (sColumnWidth != null) { rHeaderColumnFormatter.setWidth(nCol, sColumnWidth); rDataColumnFormatter.setWidth(nCol, sColumnWidth); } } }