Class TableColumnSizer
-
Method Summary
Modifier and TypeMethodDescriptionvoidaddColumnAdjustmentListener(ActionListener listener) voidAdjust the columns of the table.static TableColumnSizerAutomatically optimize the column widths of a table.voidremoveColumnAdjustmentListener(ActionListener listener) voidreset()Reset any state that relies on the contents of the table.void
-
Method Details
-
autoSize
Automatically optimize the column widths of a table. TheremainderColumnis the index of the column that will receive additional space left over after all other columns have been optimally sized. Usually this should be the largest column in the table.When
fitTableToWidthis false:All columns will be optimally sized all the time (except the
remainderColumnwhich may be larger) even if the table then exceeds its parent's width.When
fitTableToWidthis true:Columns will only be optimized if doing so results in the
remainderColumnreceiving more space than it would underJTable.AUTO_RESIZE_SUBSEQUENT_COLUMNS- resizing. Resizing behavior will fall back toJTable.AUTO_RESIZE_SUBSEQUENT_COLUMNSunder some threshold below which the latter is better.The result of this is that when widening the table, after the threshold the columns will snap into their optimal size and all additional space goes to the
remainderColumn.Also note that automatic sizing will be disabled if the user manually adjusts column widths.
- Parameters:
table-remainderColumn-fitTableToWidth-- Returns:
-
reset
public void reset()Reset any state that relies on the contents of the table. -
setRestoreAutoSizing
public void setRestoreAutoSizing() -
adjustTableColumns
public void adjustTableColumns()Adjust the columns of the table. If possible, this optimally sizes the columns such that columns greater than 0 are only as big as necessary, and the rest of the space goes to column 0. This auto-sizing only happens if it represents an improvement over the default sizing (gives more space to theremainderColumnthan it would get withJTable.AUTO_RESIZE_SUBSEQUENT_COLUMNS), and only if the user has not manually adjusted column widths. -
addColumnAdjustmentListener
-
removeColumnAdjustmentListener
-