Class AutoResizeTableColumns
- java.lang.Object
-
- gr.zeus.ui.table.AutoResizeTableColumns
-
- All Implemented Interfaces:
java.util.EventListener
,javax.swing.event.TableModelListener
public final class AutoResizeTableColumns extends java.lang.Object implements javax.swing.event.TableModelListener
NOTE: This class needs a lot of testing in order to check all possible use cases! Please usesetDebugMode(true)
and reports any bugs or malfunctions to gregkotsaftis@yahoo.comThis 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 methodsetDebugMode(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 Modifier and Type Field Description static int
DEFAULT_COLUMN_PADDING
-
Constructor Summary
Constructors Constructor 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.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
setDebugMode(boolean debugMode)
Sets debug mode.void
tableChanged(javax.swing.event.TableModelEvent tableModelEvent)
Implementation of TableModelListener.
-
-
-
Field Detail
-
DEFAULT_COLUMN_PADDING
public static final int DEFAULT_COLUMN_PADDING
- See Also:
- Constant Field Values
-
-
Constructor Detail
-
AutoResizeTableColumns
public AutoResizeTableColumns(javax.swing.JTable tbl)
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
public AutoResizeTableColumns(javax.swing.JTable tbl, boolean allColumnsLock)
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(javax.swing.JTable tbl, javax.swing.table.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 Detail
-
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
public void tableChanged(javax.swing.event.TableModelEvent tableModelEvent)
Implementation of TableModelListener.- Specified by:
tableChanged
in interfacejavax.swing.event.TableModelListener
- Parameters:
tableModelEvent
- The event.
-
-