Class AutoResizeTableColumns
- All Implemented Interfaces:
EventListener
,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!
- Since:
- 1.50
- Author:
- Gregory Kotsaftis
-
Field Summary
Fields -
Constructor Summary
ConstructorsConstructorDescriptionConstructor.AutoResizeTableColumns
(JTable tbl, boolean allColumnsLock) Constructor.AutoResizeTableColumns
(JTable tbl, TableModel mdl, int columnPadding, boolean includeHeaders, boolean includeRows, boolean[] lockColumns) Constructor. -
Method Summary
Modifier and TypeMethodDescriptionvoid
setDebugMode
(boolean debugMode) Sets debug mode.void
tableChanged
(TableModelEvent tableModelEvent) Implementation of TableModelListener.
-
Field Details
-
DEFAULT_COLUMN_PADDING
public static final int DEFAULT_COLUMN_PADDING- See Also:
-
-
Constructor Details
-
AutoResizeTableColumns
Constructor. Uses default values (includes headers and rows calculations, does not lock columns and column padding is set to 5 pixels).- Parameters:
tbl
- The table instance.
-
AutoResizeTableColumns
Constructor. Uses default values (includes headers and rows calculations, column padding is set to 5 pixels).- Parameters:
tbl
- The table instance.allColumnsLock
- true/false to lock/unlock all columns
-
AutoResizeTableColumns
public AutoResizeTableColumns(JTable tbl, TableModel mdl, int columnPadding, boolean includeHeaders, boolean includeRows, boolean[] lockColumns) Constructor.- Parameters:
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.
-
-
Method Details
-
setDebugMode
public void setDebugMode(boolean debugMode) Sets debug mode. WARNING! Enabling this will slow down your application!- Parameters:
debugMode
- true/false enable or disable the debug output.
-
tableChanged
Implementation of TableModelListener.- Specified by:
tableChanged
in interfaceTableModelListener
- Parameters:
tableModelEvent
- The event.
-