Class TableHelper


  • public final class TableHelper
    extends java.lang.Object
    The class that provide common JTable customization methods
    Since:
    5785
    • Constructor Summary

      Constructors 
      Modifier Constructor Description
      private TableHelper()  
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static void adaptTo​(IEnabledStateUpdating listener, javax.swing.ListSelectionModel listSelectionModel)
      Wires listener to listSelectionModel in such a way, that listener receives a IEnabledStateUpdating.updateEnabledState() on every ListSelectionEvent.
      static void adaptTo​(IEnabledStateUpdating listener, javax.swing.table.AbstractTableModel listModel)
      Wires listener to listModel in such a way, that listener receives a IEnabledStateUpdating.updateEnabledState() on every ListDataEvent.
      static void adjustColumnWidth​(javax.swing.JTable tbl, int col, boolean resizable)
      adjust the preferred width of column col to the maximum preferred width of the cells (including header)
      static void adjustColumnWidth​(javax.swing.JTable tbl, int col, int maxColumnWidth)
      adjust the preferred width of column col to the maximum preferred width of the cells (including header) requires JTable.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
      static void computeColumnsWidth​(javax.swing.JTable tbl)
      adjust the table's columns to fit their content best requires JTable.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
      (package private) static int getColumnHeaderWidth​(javax.swing.JTable tbl, int col)  
      (package private) static int getMaxWidth​(javax.swing.JTable tbl, int col)  
      static java.util.stream.IntStream selectedIndices​(javax.swing.ListSelectionModel selectionModel)
      Returns a stream of all of the selected indices in the selection model, in increasing order.
      static void setFont​(javax.swing.JTable table, java.lang.Class<? extends java.awt.Component> parent)
      Sets the table font size based on the font scaling from the preferences
      static void setSelectedIndices​(javax.swing.ListSelectionModel selectionModel, java.util.stream.IntStream indices)
      Selects the given indices in the selection model
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Method Detail

      • adaptTo

        public static void adaptTo​(IEnabledStateUpdating listener,
                                   javax.swing.ListSelectionModel listSelectionModel)
        Wires listener to listSelectionModel in such a way, that listener receives a IEnabledStateUpdating.updateEnabledState() on every ListSelectionEvent.
        Parameters:
        listener - the listener
        listSelectionModel - the source emitting ListSelectionEvents
        Since:
        15226
      • adaptTo

        public static void adaptTo​(IEnabledStateUpdating listener,
                                   javax.swing.table.AbstractTableModel listModel)
        Wires listener to listModel in such a way, that listener receives a IEnabledStateUpdating.updateEnabledState() on every ListDataEvent.
        Parameters:
        listener - the listener
        listModel - the source emitting ListDataEvents
        Since:
        15226
      • getMaxWidth

        static int getMaxWidth​(javax.swing.JTable tbl,
                               int col)
      • adjustColumnWidth

        public static void adjustColumnWidth​(javax.swing.JTable tbl,
                                             int col,
                                             boolean resizable)
        adjust the preferred width of column col to the maximum preferred width of the cells (including header)
        Parameters:
        tbl - table
        col - column index
        resizable - if true, resizing is allowed
        Since:
        15176
      • adjustColumnWidth

        public static void adjustColumnWidth​(javax.swing.JTable tbl,
                                             int col,
                                             int maxColumnWidth)
        adjust the preferred width of column col to the maximum preferred width of the cells (including header) requires JTable.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
        Parameters:
        tbl - table
        col - column index
        maxColumnWidth - maximum column width
      • computeColumnsWidth

        public static void computeColumnsWidth​(javax.swing.JTable tbl)
        adjust the table's columns to fit their content best requires JTable.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
        Parameters:
        tbl - table
        Since:
        14476
      • selectedIndices

        public static java.util.stream.IntStream selectedIndices​(javax.swing.ListSelectionModel selectionModel)
        Returns a stream of all of the selected indices in the selection model, in increasing order.
        Parameters:
        selectionModel - list selection model.
        Returns:
        all of the selected indices, in increasing order, or an empty stream if nothing is selected
        Since:
        17773
      • setSelectedIndices

        public static void setSelectedIndices​(javax.swing.ListSelectionModel selectionModel,
                                              java.util.stream.IntStream indices)
        Selects the given indices in the selection model
        Parameters:
        selectionModel - list selection model.
        indices - the indices to select
        Since:
        16601
        See Also:
        ListSelectionModel.addSelectionInterval(int, int)
      • setFont

        public static void setFont​(javax.swing.JTable table,
                                   java.lang.Class<? extends java.awt.Component> parent)
        Sets the table font size based on the font scaling from the preferences
        Parameters:
        table - the table
        parent - the parent component used for determining the preference key
        See Also:
        JComponent.setFont(Font), JTable.setRowHeight(int)