Class TableUtilities


  • public class TableUtilities
    extends java.lang.Object
    Collection of utility methods for J/X/Table.
    • Constructor Summary

      Constructors 
      Modifier Constructor Description
      private TableUtilities()  
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static void clear​(javax.swing.table.TableColumnModel model, boolean includeHidden)
      Removes all columns of the given column model.
      private static void clear​(javax.swing.table.TableColumnModel model, java.util.List<javax.swing.table.TableColumn> columns)  
      static int getPreferredRowHeight​(javax.swing.JTable table, int row)
      Returns the preferred height for the given row.
      static boolean isDataChanged​(javax.swing.event.TableModelEvent e)
      Returns a boolean indication whether the event represents a dataChanged type.
      static boolean isInsert​(javax.swing.event.TableModelEvent e)
      Returns a boolean indication whether the event represents a insert type.
      static boolean isStructureChanged​(javax.swing.event.TableModelEvent e)
      Returns a boolean indication whether the event represents a structureChanged type.
      static boolean isUpdate​(javax.swing.event.TableModelEvent e)
      Returns a boolean indication whether the event represents a update type.
      static int[] ordinalsOf​(java.lang.Enum<?>... values)
      Returns an array containing the ordinals of the given values of an Enum.
      static void setPreferredRowHeight​(javax.swing.JTable table, int row)  
      static void setPreferredRowHeights​(javax.swing.JTable table)
      Sets preferred row heights for all visible rows.
      • Methods inherited from class java.lang.Object

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

      • TableUtilities

        private TableUtilities()
    • Method Detail

      • isDataChanged

        public static boolean isDataChanged​(javax.swing.event.TableModelEvent e)
        Returns a boolean indication whether the event represents a dataChanged type.
        Parameters:
        e - the event to examine.
        Returns:
        true if the event is of type dataChanged, false else.
      • isUpdate

        public static boolean isUpdate​(javax.swing.event.TableModelEvent e)
        Returns a boolean indication whether the event represents a update type.
        Parameters:
        e - the event to examine.
        Returns:
        true if the event is a true update, false otherwise.
      • isInsert

        public static boolean isInsert​(javax.swing.event.TableModelEvent e)
        Returns a boolean indication whether the event represents a insert type.
        Parameters:
        e - the event to examine
        Returns:
        true if the event is of type insert, false otherwise.
      • isStructureChanged

        public static boolean isStructureChanged​(javax.swing.event.TableModelEvent e)
        Returns a boolean indication whether the event represents a structureChanged type.
        Parameters:
        e - the event to examine.
        Returns:
        true if the event is of type structureChanged or null, false else.
      • getPreferredRowHeight

        public static int getPreferredRowHeight​(javax.swing.JTable table,
                                                int row)
        Returns the preferred height for the given row. It loops across all visible columns and returns the maximal pref height of the rendering component. Falls back to the table's base rowheight, i f there are no columns or the renderers max is zeor.

        Parameters:
        table - the table which provides the renderers, must not be null
        row - the index of the row in view coordinates
        Returns:
        the preferred row height of
        Throws:
        java.lang.NullPointerException - if table is null.
        java.lang.IndexOutOfBoundsException - if the row is not a valid row index
      • setPreferredRowHeight

        public static void setPreferredRowHeight​(javax.swing.JTable table,
                                                 int row)
        Parameters:
        table - the table which provides the renderers, must not be null
        row - the index of the row in view coordinates
        Throws:
        java.lang.NullPointerException - if table is null.
        java.lang.IndexOutOfBoundsException - if the row is not a valid row index
      • setPreferredRowHeights

        public static void setPreferredRowHeights​(javax.swing.JTable table)
        Sets preferred row heights for all visible rows.
        Parameters:
        table - the table to set row heights to
        Throws:
        java.lang.NullPointerException - if no table installed.
      • ordinalsOf

        public static int[] ordinalsOf​(java.lang.Enum<?>... values)
        Returns an array containing the ordinals of the given values of an Enum.

        Convience for clients which define TableColumns as Enums (Issue #1304-swingx).

        Parameters:
        values - the enums to map to its ordinals
        Returns:
        an array of ordinals, guaranteed to be not null
      • clear

        public static void clear​(javax.swing.table.TableColumnModel model,
                                 boolean includeHidden)
        Removes all columns of the given column model. Includes hidden columns as indicated by the includesHidden flag, the flag has no effect if the model is not of type TableColumnModelExt.

        Parameters:
        model - the column model to remove all columns from.
        includeHidden - indicates whether hidden columns should be removed as well, has no effect if model is not of type TableColumnModelExt.
      • clear

        private static void clear​(javax.swing.table.TableColumnModel model,
                                  java.util.List<javax.swing.table.TableColumn> columns)