public class ColumnWidthsResizer
extends java.lang.Object
implements javax.swing.event.TableModelListener, javax.swing.event.TableColumnModelListener
JTable
's columns such that they're just big enough to display
all of their contents without truncation. Expected usage:
JTable table = new JTable(...); ColumnWidthsResizer listener = new ColumnWidthsResizer(table); table.getModel().addTableModelListener(listener); // Respond to row and data changes. table.getColumnModel().addColumnModelListener(listener); // Respond to column changes.
Modifier and Type | Field and Description |
---|---|
static int |
DEFAULT_FULL_SCAN_CUTOFF
The default maximum number of table rows for which a full scan will be performed.
|
Constructor and Description |
---|
ColumnWidthsResizer(javax.swing.JTable table)
Creates a listener that resizes
table 's column widths when its data and/or structure changes. |
ColumnWidthsResizer(javax.swing.JTable table,
int fullScanCutoff)
Creates a listener that resizes
table 's column widths when its data and/or structure changes. |
Modifier and Type | Method and Description |
---|---|
void |
columnAdded(javax.swing.event.TableColumnModelEvent e) |
void |
columnMarginChanged(javax.swing.event.ChangeEvent e) |
void |
columnMoved(javax.swing.event.TableColumnModelEvent e) |
void |
columnRemoved(javax.swing.event.TableColumnModelEvent e) |
void |
columnSelectionChanged(javax.swing.event.ListSelectionEvent e) |
static int |
getCellWidth(javax.swing.JTable table,
int rowViewIndex,
int colViewIndex) |
static void |
resize(javax.swing.JTable table) |
static void |
resize(javax.swing.JTable table,
boolean doFullScan) |
static void |
resize(javax.swing.JTable table,
int colViewIndex) |
static void |
resize(javax.swing.JTable table,
int colViewIndex,
boolean doFullScan) |
void |
tableChanged(javax.swing.event.TableModelEvent e) |
public static final int DEFAULT_FULL_SCAN_CUTOFF
public ColumnWidthsResizer(javax.swing.JTable table)
table
's column widths when its data and/or structure changes.
If table.getRowCount() <=
DEFAULT_FULL_SCAN_CUTOFF
, a full scan will be performed. That is,
every row will be examined to determine the optimal column widths. Otherwise, a partial scan will be
performed. That is, only the header and the first, middle, and last rows will be examined to determine the
approximate column widths.table
- a table.public ColumnWidthsResizer(javax.swing.JTable table, int fullScanCutoff)
table
's column widths when its data and/or structure changes.table
- a table.fullScanCutoff
- true
if a full scan should be performed; false
if a partial scan should
be done instead.public void tableChanged(javax.swing.event.TableModelEvent e)
tableChanged
in interface javax.swing.event.TableModelListener
public void columnAdded(javax.swing.event.TableColumnModelEvent e)
columnAdded
in interface javax.swing.event.TableColumnModelListener
public void columnRemoved(javax.swing.event.TableColumnModelEvent e)
columnRemoved
in interface javax.swing.event.TableColumnModelListener
public void columnMoved(javax.swing.event.TableColumnModelEvent e)
columnMoved
in interface javax.swing.event.TableColumnModelListener
public void columnMarginChanged(javax.swing.event.ChangeEvent e)
columnMarginChanged
in interface javax.swing.event.TableColumnModelListener
public void columnSelectionChanged(javax.swing.event.ListSelectionEvent e)
columnSelectionChanged
in interface javax.swing.event.TableColumnModelListener
public static void resize(javax.swing.JTable table)
public static void resize(javax.swing.JTable table, boolean doFullScan)
public static void resize(javax.swing.JTable table, int colViewIndex)
public static void resize(javax.swing.JTable table, int colViewIndex, boolean doFullScan)
public static int getCellWidth(javax.swing.JTable table, int rowViewIndex, int colViewIndex)