public final class AutoResizeTableColumns
extends java.lang.Object
implements javax.swing.event.TableModelListener
setDebugMode(true)
and reports any bugs or
malfunctions to
gregkotsaftis@yahoo.com
This class can be used to dynamically resize a JTable
, every
time it's data changes, based on header size and row data. It can also lock
any or all of the table's columns (no manual resize possible). Please note
that this class respects hidden columns (columns with all sizes set to zero)
and excludes them from the resize. Also take into consideration that if
performance is a must, you should avoid adding and removing single rows
in the table's model, to avoid multiple tableChanged() events leading to
multiple executions of this class. Instead you should store your data in
Vectors and pass them on to the table's model in a single step. Finally, you
can use the method setDebugMode(true)
in order to understand
how this class functions and the results of your own application; note that
if you enable debuging, the performance will degrade by a major degree!
Modifier and Type | Field and Description |
---|---|
static int |
DEFAULT_COLUMN_PADDING |
Constructor and Description |
---|
AutoResizeTableColumns(javax.swing.JTable tbl)
Constructor.
|
AutoResizeTableColumns(javax.swing.JTable tbl,
boolean allColumnsLock)
Constructor.
|
AutoResizeTableColumns(javax.swing.JTable tbl,
javax.swing.table.TableModel mdl,
int columnPadding,
boolean includeHeaders,
boolean includeRows,
boolean[] lockColumns)
Constructor.
|
Modifier and Type | Method and Description |
---|---|
void |
setDebugMode(boolean debugMode)
Sets debug mode.
|
void |
tableChanged(javax.swing.event.TableModelEvent tableModelEvent)
Implementation of TableModelListener.
|
public static final int DEFAULT_COLUMN_PADDING
public AutoResizeTableColumns(javax.swing.JTable tbl)
tbl
- The table instance.public AutoResizeTableColumns(javax.swing.JTable tbl, boolean allColumnsLock)
tbl
- The table instance.allColumnsLock
- true/false to lock/unlock all columnspublic AutoResizeTableColumns(javax.swing.JTable tbl, javax.swing.table.TableModel mdl, int columnPadding, boolean includeHeaders, boolean includeRows, boolean[] lockColumns)
tbl
- The table instance.mdl
- The table model.columnPadding
- The pixels to use for column padding.includeHeaders
- true/false to include headers in calculation.includeRows
- true/false to include rows in calculation.lockColumns
- An array that contains the lock status of each
individual column.public void setDebugMode(boolean debugMode)
debugMode
- true/false enable or disable the debug output.public void tableChanged(javax.swing.event.TableModelEvent tableModelEvent)
tableChanged
in interface javax.swing.event.TableModelListener
tableModelEvent
- The event.