Package ucar.ui.table

Class ColumnWidthsResizer

  • All Implemented Interfaces:
    EventListener, TableColumnModelListener, TableModelListener

    public class ColumnWidthsResizer
    extends Object
    implements TableModelListener, TableColumnModelListener
    A listener that sets the preferred widths of a 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.
     
    • 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 resizes 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.

        Parameters:
        table - a table.
      • ColumnWidthsResizer

        public ColumnWidthsResizer​(JTable table,
                                   int fullScanCutoff)
        Creates a listener that resizes table'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.