public final class TableColumnSizer
extends java.lang.Object
Modifier and Type | Method and Description |
---|---|
void |
addColumnAdjustmentListener(java.awt.event.ActionListener listener) |
void |
adjustTableColumns()
Adjust the columns of the table.
|
static TableColumnSizer |
autoSize(javax.swing.JTable table,
int remainderColumn,
boolean fitTableToWidth)
Automatically optimize the column widths of a table.
|
void |
removeColumnAdjustmentListener(java.awt.event.ActionListener listener) |
void |
reset()
Reset any state that relies on the contents of the table.
|
void |
setRestoreAutoSizing() |
public static TableColumnSizer autoSize(javax.swing.JTable table, int remainderColumn, boolean fitTableToWidth)
remainderColumn
is 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 fitTableToWidth
is false:
All columns will be optimally sized all the time (except the remainderColumn
which may be larger) even if the table then exceeds its parent's width.
When fitTableToWidth
is true:
Columns will only be optimized if doing so results in the remainderColumn
receiving more space than it would under JTable.AUTO_RESIZE_SUBSEQUENT_COLUMNS
-
resizing. Resizing behavior will fall back to JTable.AUTO_RESIZE_SUBSEQUENT_COLUMNS
under 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.
table
- remainderColumn
- fitTableToWidth
- public void reset()
public void setRestoreAutoSizing()
public void adjustTableColumns()
remainderColumn
than
it would get with JTable.AUTO_RESIZE_SUBSEQUENT_COLUMNS
),
and only if the user has not manually adjusted column widths.public void addColumnAdjustmentListener(java.awt.event.ActionListener listener)
public void removeColumnAdjustmentListener(java.awt.event.ActionListener listener)