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 intDEFAULT_FULL_SCAN_CUTOFFThe 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 voidcolumnAdded(TableColumnModelEvent e)voidcolumnMarginChanged(ChangeEvent e)voidcolumnMoved(TableColumnModelEvent e)voidcolumnRemoved(TableColumnModelEvent e)voidcolumnSelectionChanged(ListSelectionEvent e)static intgetCellWidth(JTable table, int rowViewIndex, int colViewIndex)static voidresize(JTable table)static voidresize(JTable table, boolean doFullScan)static voidresize(JTable table, int colViewIndex)static voidresize(JTable table, int colViewIndex, boolean doFullScan)voidtableChanged(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-trueif a full scan should be performed;falseif a partial scan should be done instead.
-
-
Method Detail
-
tableChanged
public void tableChanged(TableModelEvent e)
- Specified by:
tableChangedin interfaceTableModelListener
-
columnAdded
public void columnAdded(TableColumnModelEvent e)
- Specified by:
columnAddedin interfaceTableColumnModelListener
-
columnRemoved
public void columnRemoved(TableColumnModelEvent e)
- Specified by:
columnRemovedin interfaceTableColumnModelListener
-
columnMoved
public void columnMoved(TableColumnModelEvent e)
- Specified by:
columnMovedin interfaceTableColumnModelListener
-
columnMarginChanged
public void columnMarginChanged(ChangeEvent e)
- Specified by:
columnMarginChangedin interfaceTableColumnModelListener
-
columnSelectionChanged
public void columnSelectionChanged(ListSelectionEvent e)
- Specified by:
columnSelectionChangedin 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)
-
-