Class TableUtil
- java.lang.Object
-
- ch.supertomcat.supertomcatutils.gui.table.TableUtil
-
public final class TableUtil extends Object
Utility class for tables
-
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static voidapplyColWidths(JTable table, String setting)Sets column widths on a jtable Format ColumnName=###|ColumnName=###|...static voidapplyColWidths(JTable table, Map<String,Integer> map)Sets column widths on a jtablestatic voidapplyTableSortOrder(JTable table, String setting)static voidapplyTableSortOrder(JTable table, Map<String,Integer> map)static intcalculateColumnHeaderWidth(JTable table, TableColumn column)Calculate column header widthstatic intcalculateColumnHeaderWidth(JTable table, TableColumn column, int additionalChars)Calculate column header widthstatic intcalculateRowHeight(JTable table, boolean containsButtons, boolean includeTableFont)Calculate row heightstatic intcalculateRowHeight(JTable table, boolean includeTableFont, Component... dummyComponents)Calculate row heightstatic intcalculateRowHeight(JTable table, boolean includeTableFont, List<Component> dummyComponents)Calculate row heightstatic int[]convertColumnIndexToModel(JTable table, int[] viewColumns, boolean sort)Converts array of view index columns to model index columnsstatic int[]convertColumnIndexToView(JTable table, int[] modelColumns, boolean sort)Converts array of model index columns to view index columnsstatic int[]convertRowIndexToModel(JTable table, int[] viewRows, boolean sort)Converts array of view index rows to model index rowsstatic int[]convertRowIndexToView(JTable table, int[] modelRows, boolean sort)Converts array of model index rows to view index rowsstatic voidinternationalizeColumns(JTable table)Changes headervalues of the columns to internationalized versionstatic Map<String,Integer>parseColWidthsSetting(String setting)Parses a colwidth setting and returns an array of integers.static StringserializeColWidthSetting(Map<String,Integer> map)static StringserializeColWidthSetting(JTable table)static StringserializeTableSortOrderSetting(JTable table)static voidsetPreferredScrollableViewportWidth(JTable table, int characterCount)Sets the PreferredScrollableViewportSize based on font, leaving the height unchangedstatic voidsetVisibleRowCount(JTable table, int rowCount)Sets the visible row count by setting the PreferredScrollableViewportSize based on row height, leaving the width unchanged
-
-
-
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- Tablesetting- Setting
-
applyColWidths
public static void applyColWidths(JTable table, Map<String,Integer> map)
Sets column widths on a jtable- Parameters:
table- Tablemap- 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- Tablesetting- Setting
-
applyTableSortOrder
public static void applyTableSortOrder(JTable table, Map<String,Integer> map)
- Parameters:
table- Tablemap- 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- TablecharacterCount- 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- TablerowCount- Count of rows to display
-
calculateRowHeight
public static int calculateRowHeight(JTable table, boolean containsButtons, boolean includeTableFont)
Calculate row height- Parameters:
table- TablecontainsButtons- True if rows contains buttons, false otherwiseincludeTableFont- Include table font into calculation- Returns:
- Row Height
-
calculateRowHeight
public static int calculateRowHeight(JTable table, boolean includeTableFont, Component... dummyComponents)
Calculate row height- Parameters:
table- TableincludeTableFont- Include table font into calculationdummyComponents- 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- TableincludeTableFont- Include table font into calculationdummyComponents- 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- Tablecolumn- Column- Returns:
- Column Header Width
-
calculateColumnHeaderWidth
public static int calculateColumnHeaderWidth(JTable table, TableColumn column, int additionalChars)
Calculate column header width- Parameters:
table- Tablecolumn- ColumnadditionalChars- 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- TableviewRows- View Index Rowssort- 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- TablemodelRows- Model Index Rowssort- 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- TableviewColumns- View Index Columnssort- 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- TablemodelColumns- Model Index Columnssort- True if converted columns should be sorted, false otherwise- Returns:
- Converted array (view index columns)
-
-