Class TableUtil


  • public final class TableUtil
    extends Object
    Utility class for tables
    • Method Detail

      • parseColWidthsSetting

        public static Map<String,​Integer> parseColWidthsSetting​(String setting)
        Parses a colwidth setting and returns an array of integers. If the parsing fails completly null is returned. If only some values could not be parsed, then they are set to 0. Format ColumnName=###|ColumnName=###|...
        Parameters:
        setting - ColWidth-Setting
        Returns:
        Map with column names as keys and int values
      • serializeColWidthSetting

        public static String serializeColWidthSetting​(Map<String,​Integer> map)
        Parameters:
        map - Map
        Returns:
        Serialized column widths
      • serializeColWidthSetting

        public static String serializeColWidthSetting​(JTable table)
        Parameters:
        table - Table
        Returns:
        Serialized column widths
      • applyColWidths

        public static void applyColWidths​(JTable table,
                                          String setting)
        Sets column widths on a jtable Format ColumnName=###|ColumnName=###|...
        Parameters:
        table - Table
        setting - Setting
      • applyColWidths

        public static void applyColWidths​(JTable table,
                                          Map<String,​Integer> map)
        Sets column widths on a jtable
        Parameters:
        table - Table
        map - Map
      • internationalizeColumns

        public static void internationalizeColumns​(JTable table)
        Changes headervalues of the columns to internationalized version
        Parameters:
        table - Table
      • applyTableSortOrder

        public static void applyTableSortOrder​(JTable table,
                                               String setting)
        Parameters:
        table - Table
        setting - Setting
      • applyTableSortOrder

        public static void applyTableSortOrder​(JTable table,
                                               Map<String,​Integer> map)
        Parameters:
        table - Table
        map - Map
      • serializeTableSortOrderSetting

        public static String serializeTableSortOrderSetting​(JTable table)
        Parameters:
        table - Table
        Returns:
        Serialized SortOrders
      • setPreferredScrollableViewportWidth

        public static void setPreferredScrollableViewportWidth​(JTable table,
                                                               int characterCount)
        Sets the PreferredScrollableViewportSize based on font, leaving the height unchanged
        Parameters:
        table - Table
        characterCount - Count of characters to display
      • setVisibleRowCount

        public static void setVisibleRowCount​(JTable table,
                                              int rowCount)
        Sets the visible row count by setting the PreferredScrollableViewportSize based on row height, leaving the width unchanged
        Parameters:
        table - Table
        rowCount - Count of rows to display
      • calculateRowHeight

        public static int calculateRowHeight​(JTable table,
                                             boolean containsButtons,
                                             boolean includeTableFont)
        Calculate row height
        Parameters:
        table - Table
        containsButtons - True if rows contains buttons, false otherwise
        includeTableFont - Include table font into calculation
        Returns:
        Row Height
      • calculateRowHeight

        public static int calculateRowHeight​(JTable table,
                                             boolean includeTableFont,
                                             Component... dummyComponents)
        Calculate row height
        Parameters:
        table - Table
        includeTableFont - Include table font into calculation
        dummyComponents - Dummy Components, which can be provided to use them in the calculation. The preferred height of the components will be evaluated.
        Returns:
        Row Height
      • calculateRowHeight

        public static int calculateRowHeight​(JTable table,
                                             boolean includeTableFont,
                                             List<Component> dummyComponents)
        Calculate row height
        Parameters:
        table - Table
        includeTableFont - Include table font into calculation
        dummyComponents - Dummy Components, which can be provided to use them in the calculation. The preferred height of the components will be evaluated.
        Returns:
        Row Height
      • calculateColumnHeaderWidth

        public static int calculateColumnHeaderWidth​(JTable table,
                                                     TableColumn column)
        Calculate column header width
        Parameters:
        table - Table
        column - Column
        Returns:
        Column Header Width
      • calculateColumnHeaderWidth

        public static int calculateColumnHeaderWidth​(JTable table,
                                                     TableColumn column,
                                                     int additionalChars)
        Calculate column header width
        Parameters:
        table - Table
        column - Column
        additionalChars - Number of additional characters, which should be added to calculate width
        Returns:
        Column Header Width
      • convertRowIndexToModel

        public static int[] convertRowIndexToModel​(JTable table,
                                                   int[] viewRows,
                                                   boolean sort)
        Converts array of view index rows to model index rows
        Parameters:
        table - Table
        viewRows - View Index Rows
        sort - True if converted rows should be sorted, false otherwise
        Returns:
        Converted array (model index rows)
      • convertRowIndexToView

        public static int[] convertRowIndexToView​(JTable table,
                                                  int[] modelRows,
                                                  boolean sort)
        Converts array of model index rows to view index rows
        Parameters:
        table - Table
        modelRows - Model Index Rows
        sort - True if converted rows should be sorted, false otherwise
        Returns:
        Converted array (view index rows)
      • convertColumnIndexToModel

        public static int[] convertColumnIndexToModel​(JTable table,
                                                      int[] viewColumns,
                                                      boolean sort)
        Converts array of view index columns to model index columns
        Parameters:
        table - Table
        viewColumns - View Index Columns
        sort - True if converted columns should be sorted, false otherwise
        Returns:
        Converted array (model index columns)
      • convertColumnIndexToView

        public static int[] convertColumnIndexToView​(JTable table,
                                                     int[] modelColumns,
                                                     boolean sort)
        Converts array of model index columns to view index columns
        Parameters:
        table - Table
        modelColumns - Model Index Columns
        sort - True if converted columns should be sorted, false otherwise
        Returns:
        Converted array (view index columns)