Package ucar.ui.table
Class ColumnWidthsResizer
- java.lang.Object
-
- ucar.ui.table.ColumnWidthsResizer
-
- All Implemented Interfaces:
EventListener
,TableColumnModelListener
,TableModelListener
public class ColumnWidthsResizer extends Object implements TableModelListener, TableColumnModelListener
A listener that sets the preferred widths of aJTable
'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.
-
-
Field Summary
Fields Modifier and Type Field Description static int
DEFAULT_FULL_SCAN_CUTOFF
The default maximum number of table rows for which a full scan will be performed.
-
Constructor Summary
Constructors Constructor Description ColumnWidthsResizer(JTable table)
Creates a listener that resizestable
's column widths when its data and/or structure changes.ColumnWidthsResizer(JTable table, int fullScanCutoff)
Creates a listener that resizestable
's column widths when its data and/or structure changes.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description void
columnAdded(TableColumnModelEvent e)
void
columnMarginChanged(ChangeEvent e)
void
columnMoved(TableColumnModelEvent e)
void
columnRemoved(TableColumnModelEvent e)
void
columnSelectionChanged(ListSelectionEvent e)
static int
getCellWidth(JTable table, int rowViewIndex, int colViewIndex)
static void
resize(JTable table)
static void
resize(JTable table, boolean doFullScan)
static void
resize(JTable table, int colViewIndex)
static void
resize(JTable table, int colViewIndex, boolean doFullScan)
void
tableChanged(TableModelEvent e)
-
-
-
Field Detail
-
DEFAULT_FULL_SCAN_CUTOFF
public static final int DEFAULT_FULL_SCAN_CUTOFF
The default maximum number of table rows for which a full scan will be performed. If a table has more rows than this, only a partial scan will be done.- See Also:
- Constant Field Values
-
-
Constructor Detail
-
ColumnWidthsResizer
public ColumnWidthsResizer(JTable table)
Creates a listener that resizestable
's column widths when its data and/or structure changes. Iftable.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.- Parameters:
table
- a table.
-
ColumnWidthsResizer
public ColumnWidthsResizer(JTable table, int fullScanCutoff)
Creates a listener that resizestable
's column widths when its data and/or structure changes.- Parameters:
table
- a table.fullScanCutoff
-true
if a full scan should be performed;false
if a partial scan should be done instead.
-
-
Method Detail
-
tableChanged
public void tableChanged(TableModelEvent e)
- Specified by:
tableChanged
in interfaceTableModelListener
-
columnAdded
public void columnAdded(TableColumnModelEvent e)
- Specified by:
columnAdded
in interfaceTableColumnModelListener
-
columnRemoved
public void columnRemoved(TableColumnModelEvent e)
- Specified by:
columnRemoved
in interfaceTableColumnModelListener
-
columnMoved
public void columnMoved(TableColumnModelEvent e)
- Specified by:
columnMoved
in interfaceTableColumnModelListener
-
columnMarginChanged
public void columnMarginChanged(ChangeEvent e)
- Specified by:
columnMarginChanged
in interfaceTableColumnModelListener
-
columnSelectionChanged
public void columnSelectionChanged(ListSelectionEvent e)
- Specified by:
columnSelectionChanged
in interfaceTableColumnModelListener
-
resize
public static void resize(JTable table)
-
resize
public static void resize(JTable table, boolean doFullScan)
-
resize
public static void resize(JTable table, int colViewIndex)
-
resize
public static void resize(JTable table, int colViewIndex, boolean doFullScan)
-
getCellWidth
public static int getCellWidth(JTable table, int rowViewIndex, int colViewIndex)
-
-