JIDE 3.5.15

com.jidesoft.grid
Class TableUtils

java.lang.Object
  extended by com.jidesoft.grid.TableUtils

public class TableUtils
extends Object

A collection of utility methods for JTable.


Nested Class Summary
static class TableUtils.ColumnSelectionRow
          The row to keep column selection information.
 
Field Summary
static String CLIENT_PROPERTY_AUTO_RESIZE_CONSIDER_HEADER
          Client property for auto resize feature.
static String CLIENT_PROPERTY_AUTO_RESIZE_CONSIDER_VISIBLE_ROWS_ONLY
          Client property for auto resize feature.
static String CLIENT_PROPERTY_AUTO_RESIZE_HIGH_PERFORMANCE
          Client property for auto resize feature.
static String CLIENT_PROPERTY_AUTO_RESIZE_RESPECT_COLUMN_WIDTH_TABLE_MODEL
          Client property for auto resize feature.
static String CLIENT_PROPERTY_SAME_RENDERER_FOR_COLUMN
          Not used yet.
static String CLIENT_PROPERTY_TABLE_COLUMN_SNAPSHOT
          When TableColumnChooser.hideColumn(javax.swing.JTable, int) is called, we will call the code below to save the original column snapshot.
static String COLUMN_PROPERTY_DATA_TABLE_MODEL_COLUMNS
          In the saved preference string, for AggregateTable, we will append ":::DATA:::" to the column identifier for non-grouping columns so we can keep right column order.
static String COLUMN_PROPERTY_GROUP_TABLE_COUNT_COLUMN
          In the saved preference string, for GroupTable, we will append "GROUP_COUNT:::HEADER" to the column identifier for group count column so we can keep right column order.
static String COLUMN_PROPERTY_GROUP_TABLE_SEPARATE_GROUP_COLUMN
          In the saved preference string, for GroupTable, we will append "GROUP_COLUMN:::HEADER" to the column identifier for separated group column so we can keep right column order.
static String COLUMN_PROPERTY_HEADER_TABLE_MODEL_COLUMNS
          In the saved preference string, for GroupTable and AggregateTable, we will append ":::HEADER" to the column identifier for grouping columns so we can keep right column order.
static char SEPARATOR
           
 
Constructor Summary
TableUtils()
           
 
Method Summary
static void adjustColumnOrderAndWidth(JTable table, Map<String,Integer> columnIndexMap, com.jidesoft.grid.TableColumnSnapshot snapshot, String[] values, int columnCount, boolean respectColumnModel, boolean hideNewColumnsInModel)
          It's for internal use only.
static void adjustColumnOrderAndWidth(TableScrollPane pane, Map<String,Integer> columnIndexMap, com.jidesoft.grid.TableColumnSnapshot snapshot, String[] values, int columnCount, boolean respectColumnModel, boolean hideNewColumnsInModel)
          It's for internal use only.
static int[] autoResizeAllColumns(JTable table)
          Resizes the optimal width for all columns of the given table.
static int[] autoResizeAllColumns(JTable table, boolean considerHeader)
          Resizes the optimal width for all columns of the given table.
static int[] autoResizeAllColumns(JTable table, int[] minimumWidth, boolean considerHeader)
          Resizes the optimal width for all columns of the given table.
static int[] autoResizeAllColumns(JTable table, int[] minimumWidth, boolean considerHeader, boolean visibleRowsOnly)
          Resizes the optimal width for all columns of the given table.
static int[] autoResizeAllColumns(JTable table, int[] minimumWidth, int[] maximumWidth, boolean considerHeader, boolean visibleRowsOnly)
          Resizes the optimal width for all columns of the given table.
static int[] autoResizeAllColumns(JTable table, int[] minimumWidth, int[] maximumWidth, boolean considerHeader, boolean visibleRowsOnly, boolean highPerformance)
          Resizes the optimal width for all columns of the given table.
static int[] autoResizeAllColumns(JTable table, int[] minimumWidth, int[] maximumWidth, boolean considerHeader, boolean visibleRowsOnly, boolean highPerformance, boolean respectColumnWidthTableModel)
          Resizes the optimal width for all columns of the given table.
static int[] autoResizeAllRows(JTable table)
          Calculates the optimal height for the row of the given table.
static int[] autoResizeAllRows(JTable table, int[] minimumHeight)
          Calculates the optimal height for the row of the given table.
static int autoResizeColumn(JTable table, int col)
          Resizes the optimal width for the column of the given table.
static int autoResizeColumn(JTable table, int col, boolean considerHeader)
          Resizes the optimal width for the column of the given table.
static int autoResizeColumn(JTable table, int col, boolean considerHeader, boolean visibleRowsOnly)
          Resizes the optimal width for the column of the given table.
static int autoResizeColumn(JTable table, int col, boolean considerHeader, boolean visibleRowsOnly, int minimumWidth)
          Resizes the optimal width for the column of the given table.
static int autoResizeColumn(JTable table, int col, boolean considerHeader, boolean visibleRowsOnly, int minimumWidth, int maximumWidth)
          Resizes the optimal width for the column of the given table.
static int autoResizeColumn(JTable table, int col, boolean considerHeader, boolean visibleRowsOnly, int minimumWidth, int maximumWidth, boolean highPerformance)
          Resizes the optimal width for the column of the given table.
static int autoResizeColumn(JTable table, int col, boolean considerHeader, boolean visibleRowsOnly, int minimumWidth, int maximumWidth, boolean highPerformance, boolean respectColumnWidthTableModel)
          Resizes the optimal width for the column of the given table.
static int autoResizeRow(JTable table, int row)
          Calculates the optimal height for the row of the given table.
static int autoResizeRow(JTable table, int row, int minimumHeight)
          Calculates the optimal height for the row of the given table.
static int[] autoResizeRows(JTable table, int fromRow, int toRow)
          Calculates the optimal height for the rows of the given table.
static int[] autoResizeRows(JTable table, int fromRow, int toRow, int[] minimumHeight)
          Calculates the optimal height for the rows of the given table.
protected static int calculateRowHeight(JTable table, int row, int minimumHeight)
           
static void clearColumnOrdersMemory(JTable table)
           
static void clearColumnOrdersMemory(TableScrollPane pane)
           
static void ensureRowSelectionVisible(JTable table)
          To make sure the selected row is visible.
static void ensureRowVisible(JTable table, int row)
          To make sure the row is visible.
static Object eraseIdentifierFlag(Object identifier, String flag)
           
static int findColumnIndex(TableModel model, String columnName)
          Finds the column that has the columnName.
static int[] findColumnIndexes(TableModel model, String[] columnNames)
          Finds the column indexes that has the name specified in the columnNames array.
static int getAutoResizeExtraWidth()
          Gets the value of extra width we will add to calculated column width when we do autoResizeAllColumns(javax.swing.JTable) or autoResizeColumn(javax.swing.JTable, int).
static String getFilterableTableModelPreference(IFilterableTableModel model)
          Gets the preference string of the filterable table model, which includes the filters.
static TableColumn getResizingColumn(JTable table, Point p, int column)
          Get the resizing column instance based on the table and point and the column.
static String getSortableTablePreference(SortableTable table)
          Gets the sortable table sorting order as String.
static String getSortableTablePreference(SortableTable table, boolean saveColumName)
          Gets the sortable table sorting order as String.
static String getTablePreference(JTable table)
          Deprecated. replaced by getTablePreferenceByName(javax.swing.JTable)
static String getTablePreferenceByName(JTable table)
          Gets the table preference string.
static String getTablePreferenceByName(TableScrollPane pane)
          Gets the table preference string.
static int getViewPositionForRow(JTable table, int row)
          Gets the view y position for the row in a table.
static boolean isTableColumnResizable(JTable table, TableColumn column)
          Checks if the table column is resizable.
static void loadRowHeights(JTable table, int[] rowHeights)
          Load row heights from the saved integer array.
static void loadSelection(JTable table, int[] selected)
          Restore the selection in JTable.
static void loadSelection(JTable table, int[] selected, boolean scrollSelectionToVisible)
          Restore the selection in JTable.
static void loadSelection(TreeTable table, Row[] selectedRows)
          Restore the selection in TreeTable.
static void loadSelection(TreeTable table, Row[] selectedRows, boolean scrollSelectionToVisible)
          Restore the selection in TreeTable.
static void loadSelection(TreeTable table, Row[] selectedRows, boolean scrollSelectionToVisible, boolean compareCurrentSelection)
          Restore the selection in TreeTable.
static void loadTreeTableRowHeights(TreeTable table, Map<Row,Integer> rowHeightsMap)
          Load row heights from the saved integer array.
protected static int nextRow(JTable table, JTable nextTable)
           
protected static int previousRow(JTable table, JTable prevTable)
           
static void saveColumnOrders(JTable table, boolean isUngroup)
           
static void saveColumnOrders(TableScrollPane pane)
           
static void saveDefaultColumnOrders(GroupTable table)
           
static void saveDefaultColumnOrders(TableScrollPane pane, TableModel model)
           
static int[] saveRowHeights(JTable table)
          Save the heights of the table to an integer array.
static int[] saveSelection(JTable table)
          Save the selection of the JTable as an array of integer.
static Row[] saveSelection(TreeTable table)
          Save the selection of the TreeTable as an array of Rows.
static Map<Row,Integer> saveTreeTableRowHeights(TreeTable table)
          Save the heights of the tree table to a map.
static void setAutoResizeExtraWidth(int autoResizeExtraWidth)
          We will add 4 pixels extra width to the calculated column width when we do autoResizeAllColumns(javax.swing.JTable) or autoResizeColumn(javax.swing.JTable, int).
static boolean setFilterableTableModelPreference(IFilterableTableModel model, String pref)
          Sets the preference string back to the filterable table model to load the preference including filters.
static boolean setSortableTablePreference(SortableTable table, String pref)
          Sets the sortable table sorting order preference string that was saved before to the table.
static boolean setSortableTablePreference(SortableTable table, String pref, boolean saveColumnName)
          Sets the sortable table sorting order preference string that was saved before to the table.
static boolean setTableColumnWidthByName(JTable table, String pref)
          Sets the table preference string that was saved before to the table.
static boolean setTableColumnWidthByName(TableScrollPane pane, String pref)
          Sets the table preference string that was saved before to the TableScollPane.
static boolean setTablePreference(JTable table, String pref)
          Deprecated. replaced by setTablePreferenceByName(javax.swing.JTable, String)
static boolean setTablePreferenceByName(JTable table, String pref)
          Sets the table preference string that was saved before to the table.
static boolean setTablePreferenceByName(JTable table, String pref, boolean respectColumnModel)
          Sets the table preference string that was saved before to the table.
static boolean setTablePreferenceByName(JTable table, String pref, boolean respectColumnModel, boolean hideNewColumnsInModel)
          Sets the table preference string that was saved before to the table.
static boolean setTablePreferenceByName(TableScrollPane pane, String pref)
          Sets the table preference string that was saved before to the table.
static boolean setTablePreferenceByName(TableScrollPane pane, String pref, boolean respectColumnModel)
          Sets the table preference string that was saved before to the table.
static boolean setTablePreferenceByName(TableScrollPane pane, String pref, boolean respectColumnModel, boolean hideNewColumnsInModel)
          Sets the table preference string that was saved before to the table.
static void setViewPositionForRow(JTable table, int row, int position)
          Sets the view y position for the row in a table.
static boolean stopCellEditingForAll(JTable table)
          Stops editing for the table, including all tables in the same TableScrollPane.
static void synchronizeDropLocation(JTable[] tables)
           
static void synchronizeNavigationKeys(JTable[] tableArray)
          Synchronizes the navigation keys.
static void synchronizeNavigationKeys(JTable[][] tables)
          Synchronizes the navigation keys.
static void synchronizeRowHeight(JTable[] tables)
          Synchronizes the table height of the list of tables to be the same.
static void synchronizeRowHeights(JTable[] tables)
          Synchronizes the table row heights and table header height.
static void synchronizeSorting(JTable[] tables)
           
static void synchronizeTableAndColumnsWidth(JTable master, JTable slave)
          Synchronizes the two table columns width as well as the whole table width.
static void synchronizeTableColumn(JTable master, JTable slave)
          Synchronize two tables' columns so that the corresponding table column in both tables have the same width, at the same position.
static void synchronizeTableColumnSelection(JTable master, JTable slave)
          Makes the master table and slave table using the same SelectionModel so that when any selection change in master table will be reflected in slave table too.
static void synchronizeTableColumnWidth(JTable[] tables)
          Synchronize two tables' columns so that the corresponding table column in both tables have the same width, at the same position.
static void synchronizeTableColumnWidth(JTable master, JTable slave)
          Synchronize two tables' columns so that the corresponding table column in both tables have the same width.
static void synchronizeTableColumnWidthNow(JTable master, JTable slave)
           
static void synchronizeTableRowSelection(JTable[] tables)
          Synchronizes the row selection of the tables so that if any rows in one table is selected, the same rows in all tables will be selected too.
static void synchronizeTables(JTable[] tables)
          Links the tables in the table array so that they look like one table.
static void synchronizeTables(JTable[] tables, boolean rowSelectionAllowed, boolean columnSelectionAllowed)
          Links the tables in the table array so that they look like one table.
static void synchronizeTables(JTable[] tables, boolean rowSelectionAllowed, boolean columnSelectionAllowed, boolean nonContiguousSelectionAllowed)
          Links the tables in the table array so that they look like one table.
static void unifyTableCellEditing(JTable[] tables)
          Unifies the column selection into one selection so that only one column can be selected in all tables.
static void unifyTableCellSelection(JTable[] tables)
          Unifies the mixed cell selection into one selection so that only one cell can be selected in all tables.
static void unifyTableCellSelection(JTable[] tables, JTable stayTable)
          Unifies the mixed cell selection into one selection so that only one cell can be selected in all tables.
static void unifyTableColumnSelection(JTable[] tables)
          Unifies the column selection into one selection so that only one column can be selected in all tables.
static void unifyTableNonContiguousCellSelection(JTable[] tables)
          Unifies the non-contiguous cell selection into one selection so that only one cell can be selected in all tables.
static void unifyTableRowSelection(JTable[] tables)
          Unifies the row selection into one selection so that only one row can be selected in all tables.
static void unsynchronizeNavigationKeys(JTable[] tables)
          Unsynchronizes the navigation keys.
static void unsynchronizeNavigationKeys(JTable[][] tables)
          Unsynchronizes the navigation keys.
static void unsynchronizeTableColumn(JTable master, JTable slave)
          The reverse action of synchronizeTableColumn(javax.swing.JTable, javax.swing.JTable).
static void unsynchronizeTableColumnSelection(JTable master, JTable slave)
          The reverse action of synchronizeTableColumnSelection(javax.swing.JTable, javax.swing.JTable).
static void unsynchronizeTableRowSelection(JTable[] tables)
          UnSynchronizes the row selection of the tables.
static void ununifyTableCellEditing(JTable[] tables)
          Reverts the unification of the table celling by unifyTableCellEditing(javax.swing.JTable[]).
static void ununifyTableCellSelection(JTable[] tables)
          Reverts the unification of the cell selection by unifyTableCellSelection(javax.swing.JTable[]).
static void ununifyTableColumnSelection(JTable[] tables)
          Reverts the unification of the column selection by unifyTableColumnSelection(javax.swing.JTable[]).
static void ununifyTableNonContiguousCellSelection(JTable[] tables)
          Reverts the unification of the cell selection by unifyTableNonContiguousCellSelection(javax.swing.JTable[]).
static void ununifyTableRowSelection(JTable[] tables)
          Reverts the unification of the row selection by unifyTableRowSelection(javax.swing.JTable[]).
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

CLIENT_PROPERTY_AUTO_RESIZE_CONSIDER_HEADER

public static final String CLIENT_PROPERTY_AUTO_RESIZE_CONSIDER_HEADER
Client property for auto resize feature. If the value of this client property is Boolean.FALSE, it will not consider header column preferred width when auto resizing. Otherwise, it will consider.

See Also:
Constant Field Values

CLIENT_PROPERTY_AUTO_RESIZE_CONSIDER_VISIBLE_ROWS_ONLY

public static final String CLIENT_PROPERTY_AUTO_RESIZE_CONSIDER_VISIBLE_ROWS_ONLY
Client property for auto resize feature. If the value of this client property is Boolean.TRUE, it will consider visible rows only when when auto resizing. Otherwise, it will consider all rows.

See Also:
Constant Field Values

CLIENT_PROPERTY_AUTO_RESIZE_HIGH_PERFORMANCE

public static final String CLIENT_PROPERTY_AUTO_RESIZE_HIGH_PERFORMANCE
Client property for auto resize feature. If the value of this client property is Boolean.TRUE, it will calculate the column width in an optimized way assuming that the longest string requests the maximum width for the column. This approach will have higher performance. However, if you have different fonts for different cells, it may not be that accurate.

Since:
3.1.1
See Also:
Constant Field Values

CLIENT_PROPERTY_AUTO_RESIZE_RESPECT_COLUMN_WIDTH_TABLE_MODEL

public static final String CLIENT_PROPERTY_AUTO_RESIZE_RESPECT_COLUMN_WIDTH_TABLE_MODEL
Client property for auto resize feature. If the value of this client property is Boolean.TRUE, it will calculate the column width in an optimized way assuming that the longest string requests the maximum width for the column. This approach will have higher performance. However, if you have different fonts for different cells, it may not be that accurate.

Since:
3.2.4
See Also:
Constant Field Values

CLIENT_PROPERTY_SAME_RENDERER_FOR_COLUMN

public static final String CLIENT_PROPERTY_SAME_RENDERER_FOR_COLUMN
Not used yet.

See Also:
Constant Field Values

CLIENT_PROPERTY_TABLE_COLUMN_SNAPSHOT

public static final String CLIENT_PROPERTY_TABLE_COLUMN_SNAPSHOT
When TableColumnChooser.hideColumn(javax.swing.JTable, int) is called, we will call the code below to save the original column snapshot. We will use this snapshot to get the correct view order.
 table.putClientProperty(CLIENT_PROPERTY_TABLE_COLUMN_SNAPSHOT , snapshot);
 

See Also:
Constant Field Values

COLUMN_PROPERTY_HEADER_TABLE_MODEL_COLUMNS

public static final String COLUMN_PROPERTY_HEADER_TABLE_MODEL_COLUMNS
In the saved preference string, for GroupTable and AggregateTable, we will append ":::HEADER" to the column identifier for grouping columns so we can keep right column order.

In normal case, you don't have to use this flag. If you want to save a clear string to XML, you could erase those flags. However, when you need load them back, you have to add the flags back, otherwise, the column order could be unexpectedly changed.

See Also:
Constant Field Values

COLUMN_PROPERTY_DATA_TABLE_MODEL_COLUMNS

public static final String COLUMN_PROPERTY_DATA_TABLE_MODEL_COLUMNS
In the saved preference string, for AggregateTable, we will append ":::DATA:::" to the column identifier for non-grouping columns so we can keep right column order.

In normal case, you don't have to use this flag. If you want to save a clear string to XML, you could erase those flags. However, when you need load them back, you have to add the flags back, otherwise, the column order could be unexpectedly changed.

See Also:
Constant Field Values

COLUMN_PROPERTY_GROUP_TABLE_COUNT_COLUMN

public static final String COLUMN_PROPERTY_GROUP_TABLE_COUNT_COLUMN
In the saved preference string, for GroupTable, we will append "GROUP_COUNT:::HEADER" to the column identifier for group count column so we can keep right column order.

In normal case, you don't have to use this flag. If you want to save a clear string to XML, you could erase those flags. However, when you need load them back, you have to add the flags back, otherwise, the column order could be unexpectedly changed.

See Also:
Constant Field Values

COLUMN_PROPERTY_GROUP_TABLE_SEPARATE_GROUP_COLUMN

public static final String COLUMN_PROPERTY_GROUP_TABLE_SEPARATE_GROUP_COLUMN
In the saved preference string, for GroupTable, we will append "GROUP_COLUMN:::HEADER" to the column identifier for separated group column so we can keep right column order.

In normal case, you don't have to use this flag. If you want to save a clear string to XML, you could erase those flags. However, when you need load them back, you have to add the flags back, otherwise, the column order could be unexpectedly changed.

See Also:
Constant Field Values

SEPARATOR

public static final char SEPARATOR
See Also:
Constant Field Values
Constructor Detail

TableUtils

public TableUtils()
Method Detail

saveRowHeights

public static int[] saveRowHeights(JTable table)
Save the heights of the table to an integer array.

The first element is the row count of its inner most table model.

The second element is table.getRowHeight().

After the first two elements, every two element is a pair, the first one of the pair is the row index while the second one is its row height if different with table.getRowHeight().

Parameters:
table - the table to save row heights
Returns:
an integer array of the row heights.

saveTreeTableRowHeights

public static Map<Row,Integer> saveTreeTableRowHeights(TreeTable table)
Save the heights of the tree table to a map.

Parameters:
table - the tree table to save row heights
Returns:
an integer array of the row heights.
Since:
3.1.1

loadTreeTableRowHeights

public static void loadTreeTableRowHeights(TreeTable table,
                                           Map<Row,Integer> rowHeightsMap)
Load row heights from the saved integer array.

Parameters:
table - the tree table to be loaded
rowHeightsMap - saved row heights map by saveTreeTableRowHeights(TreeTable)
Since:
3.1.1
See Also:
saveTreeTableRowHeights(TreeTable)

loadRowHeights

public static void loadRowHeights(JTable table,
                                  int[] rowHeights)
Load row heights from the saved integer array.

Parameters:
table - the table to be loaded
rowHeights - saved row heights by saveRowHeights(javax.swing.JTable)
See Also:
saveRowHeights(javax.swing.JTable)

saveSelection

public static int[] saveSelection(JTable table)
Save the selection of the JTable as an array of integer. It works for all cases either row selection is allowed or column selection or cell selection is allowed. However you cannot change the row/column selection allowed attribute between saveSelection and loadSelection.

If the table is a JideTable and uses non contiguous selection mode, the first 2 elements are leader selection row/colum, the following 2 elements are anchor selection row/column. Then after every two elements represent a selected cell (row/column).

If the table uses column selection, the first 2 elements are leader selection row/colum, the following 2 elements are anchor selection row/column. Then after every element represents a selected column.

If the table uses row selection, the first 2 elements are leader selection row/colum, the following 2 elements are anchor selection row/column. Then after every element represents a selected row.

If the table uses cell selection, the first 2 elements are leader selection row/colum, the following 2 elements are anchor selection row/column. Then after every two elements represent a selected cell (row/column).

Parameters:
table - the table
Returns:
selection as an array

loadSelection

public static void loadSelection(JTable table,
                                 int[] selected)
Restore the selection in JTable. It must used the array that created by saveSelection. Internally it will call loadSelection(javax.swing.JTable, int[], boolean) with the scrollSelectionToVisible set to JComponent.getAutoscrolls().

Parameters:
table - the table
selected - an int array created by saveSelection

loadSelection

public static void loadSelection(JTable table,
                                 int[] selected,
                                 boolean scrollSelectionToVisible)
Restore the selection in JTable. It must used the array that created by saveSelection.

Parameters:
table - the table
selected - an int array created by saveSelection
scrollSelectionToVisible - if the table is row selection mode and this flag is true, this method will scroll the selected rows to visible.

saveSelection

public static Row[] saveSelection(TreeTable table)
Save the selection of the TreeTable as an array of Rows. It only works for when row selection is allowed. The returned Row array can be used in loadSelection(TreeTable, Row[]) to restore the selection.

The last element of the returned array will be an instance of TableUtils.ColumnSelectionRow, which is added since 3.3.1 to keep column selection.

Parameters:
table - the table
Returns:
selection as a Row array
See Also:
loadSelection(TreeTable, Row[])

loadSelection

public static void loadSelection(TreeTable table,
                                 Row[] selectedRows)
Restore the selection in TreeTable. It must used the array that created by saveSelection(TreeTable).

Parameters:
table - the tree table
selectedRows - a Row array created by saveSelection

loadSelection

public static void loadSelection(TreeTable table,
                                 Row[] selectedRows,
                                 boolean scrollSelectionToVisible)
Restore the selection in TreeTable. It must used the array that created by saveSelection(TreeTable).

In the scenario like collapse rows, if the selected rows is not visible any more, we would put its selection to its first visible ancient.

Parameters:
table - the tree table
selectedRows - a Row array created by saveSelection
scrollSelectionToVisible - if the table is row selection mode and this flag is true, this method will scroll the selected rows to visible.

loadSelection

public static void loadSelection(TreeTable table,
                                 Row[] selectedRows,
                                 boolean scrollSelectionToVisible,
                                 boolean compareCurrentSelection)
Restore the selection in TreeTable. It must used the array that created by saveSelection(TreeTable).

In the scenario like collapse rows, if the selected rows is not visible any more, we would put its selection to its first visible ancient.

Parameters:
table - the tree table
selectedRows - a Row array created by saveSelection
scrollSelectionToVisible - if the table is row selection mode and this flag is true, this method will scroll the selected rows to visible.
compareCurrentSelection - if current selection will be compared with the selection to load. By default, the value is false for performance reason. You could turn this flag to true if you care more about the selection events.

eraseIdentifierFlag

public static Object eraseIdentifierFlag(Object identifier,
                                         String flag)

getTablePreferenceByName

public static String getTablePreferenceByName(JTable table)
Gets the table preference string. The preference string contains the information such as each table column width, column order and column visibilities. If the table column width or order or visibility is changed after getTablePreference is called, setTablePreference() will change table column width, order and visibility to the previous state when this preference string is saved.

The method is designed for single table only. If you are trying to save table preference for TableScrollPane, please use getTablePreferenceByName(TableScrollPane).

Please note, this method deprecate getTablePreference(javax.swing.JTable), this method will save the column name as defined in TableModel's getColumnName method. So as long as the column name doesn't change, you can use setTablePreferenceByName(javax.swing.JTable, String) to restore correctly, even if you add or remove columns between get and set. Please also note, since the column names can be localized and sometimes can be duplicated, you can implement ColumnIdentifierTableModel and provides a unique column identifier for each column. This method will use the identifier returned from ColumnIdentifierTableModel's getColumnIdentifier method.

Comparing with the preference string you generated before release 2.5.0. Here are some differences you way want to know:

1, Added a column order part after "\t\t\t". That means the string part before that token has the same intend with the older version. Since column order persistence is not easy to achieve only with the hide information stored in previous version, we have to keep as many history information as we can so that we can restore the column order correctly.

2, We will have to calculate appropriate column order based on the history information in part 2 of the string after "\t\t\t". So it's hard to say which column should be in which column index now from the preference string itself. Actually we have an algorithm, which is invoked by setTablePreferenceByName internally to calculate it.

3, Since we have added another part to restore the column order and hidden information, we don't put -1 as width for hidden columns any more in the first part.

4, We considered backward-compatibility while making these changes. That means, if you have a preference string generated by getTablePreferenceByName in older version, you should be able to use it to reload the grid by setTablePreferenceByName in the newest version. However, getTablePreference is already deprecated and probably the string it generated is not able to use any more.

Parameters:
table - the table
Returns:
table preference string.

getTablePreferenceByName

public static String getTablePreferenceByName(TableScrollPane pane)
Gets the table preference string. The preference string contains the information such as each table column width, column order and column visibilities. If the table column width or order or visibility is changed after getTablePreference is called, setTablePreference() will change table column width, order and visibility to the previous state when this preference string is saved.

The method is designed for TableScrollPane. So you don't have to save the tables one by one in your table scroll pane.

this method will save the column name as defined in TableModel's getColumnName method. So as long as the column name doesn't change, you can use setTablePreferenceByName(javax.swing.JTable, String) to restore correctly, even if you add or remove columns between get and set. Please also note, since the column names can be localized and sometimes can be duplicated, you can implement ColumnIdentifierTableModel and provides a unique column identifier for each column. This method will use the identifier returned from ColumnIdentifierTableModel's getColumnIdentifier method.

Parameters:
pane - the table scroll pane
Returns:
table preference string.

setTablePreferenceByName

public static boolean setTablePreferenceByName(JTable table,
                                               String pref)
Sets the table preference string that was saved before to the table. This method will only restore correctly if the string is saved by getTablePreferenceByName(javax.swing.JTable).

The method is designed for single table only. If you are trying to set table preference for TableScrollPane, please use setTablePreferenceByName(TableScrollPane, String).

Parameters:
table - the table
pref - the preference string. If the value is null or if the string is not saved from the table as specified in table parameter, this method will simply return and won't change the table at all.
Returns:
true if the preference is set correctly. Otherwise false.

setTablePreferenceByName

public static boolean setTablePreferenceByName(JTable table,
                                               String pref,
                                               boolean respectColumnModel)
Sets the table preference string that was saved before to the table. This method will only restore correctly if the string is saved by getTablePreferenceByName(javax.swing.JTable).

The method is designed for single table only. If you are trying to set table preference for TableScrollPane, please use setTablePreferenceByName(TableScrollPane, String).

Parameters:
table - the table
pref - the preference string. If the value is null or if the string is not saved from the table as specified in table parameter, this method will simply return and won't change the table at all.
respectColumnModel - the default value is true so that you'll just keep the visible columns in columnModel. However, if you want to respsect the table model instead, you need set it to false.
Returns:
true if the preference is set correctly. Otherwise false.

setTablePreferenceByName

public static boolean setTablePreferenceByName(JTable table,
                                               String pref,
                                               boolean respectColumnModel,
                                               boolean hideNewColumnsInModel)
Sets the table preference string that was saved before to the table. This method will only restore correctly if the string is saved by getTablePreferenceByName(javax.swing.JTable).

The method is designed for single table only. If you are trying to set table preference for TableScrollPane, please use setTablePreferenceByName(TableScrollPane, String).

To make this utility method work as expected, please make sure your column identifiers do not contain any special characters like line break, tab, etc. Please let your table model implement ColumnIdentifierTableModel so that your table header could display those special characters without breaking this method.

Parameters:
table - the table
pref - the preference string. If the value is null or if the string is not saved from the table as specified in table parameter, this method will simply return and won't change the table at all.
respectColumnModel - the default value is true so that you'll just keep the visible columns in columnModel. However, if you want to respect the table model instead, you need set it to false.
hideNewColumnsInModel - the default value is false. If you changed the table model and you don't want the new columns visible after this call, please set the parameter to false.
Returns:
true if the preference is set correctly. Otherwise false.

setTablePreferenceByName

public static boolean setTablePreferenceByName(TableScrollPane pane,
                                               String pref)
Sets the table preference string that was saved before to the table. This method will only restore correctly if the string is saved by getTablePreferenceByName(TableScrollPane).

The method is designed for TableScrollPane. So you don't have to set the table preference one by one in your table scroll pane.

Parameters:
pane - the table scroll pane
pref - the preference string. If the value is null or if the string is not saved from the table as specified in table parameter, this method will simply return and won't change the table at all.
Returns:
true if the preference is set correctly. Otherwise false.

setTablePreferenceByName

public static boolean setTablePreferenceByName(TableScrollPane pane,
                                               String pref,
                                               boolean respectColumnModel)
Sets the table preference string that was saved before to the table. This method will only restore correctly if the string is saved by getTablePreferenceByName(TableScrollPane).

The method is designed for TableScrollPane. So you don't have to set the table preference one by one in your table scroll pane.

Parameters:
pane - the table scroll pane
pref - the preference string. If the value is null or if the string is not saved from the table as specified in table parameter, this method will simply return and won't change the table at all.
respectColumnModel - the default value is true so that you'll just keep the visible columns in columnModel. However, if you want to respect the table model instead, you need set it to false.
Returns:
true if the preference is set correctly. Otherwise false.

setTablePreferenceByName

public static boolean setTablePreferenceByName(TableScrollPane pane,
                                               String pref,
                                               boolean respectColumnModel,
                                               boolean hideNewColumnsInModel)
Sets the table preference string that was saved before to the table. This method will only restore correctly if the string is saved by getTablePreferenceByName(TableScrollPane).

The method is designed for TableScrollPane. So you don't have to set the table preference one by one in your table scroll pane.

Parameters:
pane - the table scroll pane
pref - the preference string. If the value is null or if the string is not saved from the table as specified in table parameter, this method will simply return and won't change the table at all.
respectColumnModel - the default value is true so that you'll just keep the visible columns in columnModel. However, if you want to respect the table model instead, you need set it to false.
hideNewColumnsInModel - the default value is false. If you changed the table model and you don't want the new columns visible after this call, please set the parameter to false.
Returns:
true if the preference is set correctly. Otherwise false.

adjustColumnOrderAndWidth

public static void adjustColumnOrderAndWidth(JTable table,
                                             Map<String,Integer> columnIndexMap,
                                             com.jidesoft.grid.TableColumnSnapshot snapshot,
                                             String[] values,
                                             int columnCount,
                                             boolean respectColumnModel,
                                             boolean hideNewColumnsInModel)
It's for internal use only.

Parameters:
table - the table
columnIndexMap - column index map
snapshot - column order snapshot
values - saved column width values
columnCount - saved column count
respectColumnModel - a flag
hideNewColumnsInModel - a flag

adjustColumnOrderAndWidth

public static void adjustColumnOrderAndWidth(TableScrollPane pane,
                                             Map<String,Integer> columnIndexMap,
                                             com.jidesoft.grid.TableColumnSnapshot snapshot,
                                             String[] values,
                                             int columnCount,
                                             boolean respectColumnModel,
                                             boolean hideNewColumnsInModel)
It's for internal use only.

Parameters:
pane - table scroll pane
columnIndexMap - column index map
snapshot - column order snapshot
values - saved column width values
columnCount - saved column count
respectColumnModel - the flag
hideNewColumnsInModel - a flag

setTableColumnWidthByName

public static boolean setTableColumnWidthByName(JTable table,
                                                String pref)
Sets the table preference string that was saved before to the table. This method will only restore correctly if the string is saved by getTablePreferenceByName(javax.swing.JTable). Different from setTablePreferenceByName(javax.swing.JTable, String), this method only restores the column width but not the column order.

Parameters:
table - the table
pref - the preference string. If the value is null or if the string is not saved from the table as specified in table parameter, this method will simply return and won't change the table at all.
Returns:
true if the preference is set correctly. Otherwise false.

setTableColumnWidthByName

public static boolean setTableColumnWidthByName(TableScrollPane pane,
                                                String pref)
Sets the table preference string that was saved before to the TableScollPane. This method will only restore correctly if the string is saved by getTablePreferenceByName(TableScrollPane). Different from setTablePreferenceByName(TableScrollPane, String), this method only restores the column width but not the column order.

Parameters:
pane - the table scroll pane
pref - the preference string. If the value is null or if the string is not saved from the table scroll pane as specified in table parameter, this method will simply return and won't change the table scroll pane at all.
Returns:
true if the preference is set correctly. Otherwise false.

getTablePreference

@Deprecated
public static String getTablePreference(JTable table)
Deprecated. replaced by getTablePreferenceByName(javax.swing.JTable)

Gets the table preference string. The preference string contains the information such as each table column width, column order and column visibilities. If the table column width or order or visibility is changed after getTablePreference is called, setTablePreference() will change table column width, order and visibility to the previous state when is preference string is saved.

Please note, different from getTablePreferenceByName(javax.swing.JTable), this method will save only save the column index. So if the column order changes, setTablePreference(javax.swing.JTable, String) might restore it incorrectly. Or if the column count changes, setTablePreference will simply return without even trying to restore.

Parameters:
table - the table
Returns:
table preference string.

setTablePreference

@Deprecated
public static boolean setTablePreference(JTable table,
                                                    String pref)
Deprecated. replaced by setTablePreferenceByName(javax.swing.JTable, String)

Sets the table preference string that was saved before to the table.

Note: This method works only if all columns in the TableColumnModel are there in the TableModel. If you manually add a column to TableColumnModel without adding it to TableModel, this method won't work.

Parameters:
table - the table
pref - the preference string. If the value is null or if the string is not saved from the table as specified in table parameter, this method will simply return and won't change the table at all.
Returns:
true if the preference is set correctly. Otherwise false.

getFilterableTableModelPreference

public static String getFilterableTableModelPreference(IFilterableTableModel model)
Gets the preference string of the filterable table model, which includes the filters.

Only those filters that Filter.getPreference(Class, com.jidesoft.converter.ConverterContext) is implemented could be persisted. To be loaded back correctly, the default constructor of the filter has to be public and the method Filter.setPreference(String, Class, com.jidesoft.converter.ConverterContext) needs to be implemented.

Parameters:
model - the IFilterableTableModel
Returns:
the preference string.
Since:
3.4.4

setFilterableTableModelPreference

public static boolean setFilterableTableModelPreference(IFilterableTableModel model,
                                                        String pref)
Sets the preference string back to the filterable table model to load the preference including filters.

Parameters:
model - the IFilterableTableModel
pref - the preference string
Returns:
true if at least one filter is loaded correctly from the preference string. Otherwise false.
Since:
3.4.4
See Also:
getFilterableTableModelPreference(IFilterableTableModel)

getSortableTablePreference

public static String getSortableTablePreference(SortableTable table)
Gets the sortable table sorting order as String. The preference string contains the information such as table column sorting order. If the table sorting order is changed after getSortableTablePreference is called, setSortableTablePreference() will restore the sort order.

Parameters:
table - the table
Returns:
sortable table preference string.

getSortableTablePreference

public static String getSortableTablePreference(SortableTable table,
                                                boolean saveColumName)
Gets the sortable table sorting order as String. The preference string contains the information such as table column sorting order. If the table sorting order is changed after getSortableTablePreference is called, setSortableTablePreference() will restore the sort order.

Parameters:
table - the table
saveColumName - true or false. If true, we will keep the column name or identifier in the preference string instead of using column index. If your TableModel's column index (please note, not TableColumnModel) could change but the column name or identifier never changes, you should use true as the parameter.
Returns:
sortable table preference string.

setSortableTablePreference

public static boolean setSortableTablePreference(SortableTable table,
                                                 String pref)
Sets the sortable table sorting order preference string that was saved before to the table.

Parameters:
table - the table
pref - the preference string. If the value is null or if the string is not saved from the table as specified in table parameter, this method will simply return and won't change the table at all.
Returns:
true if the preference is set correctly. Otherwise false.

setSortableTablePreference

public static boolean setSortableTablePreference(SortableTable table,
                                                 String pref,
                                                 boolean saveColumnName)
Sets the sortable table sorting order preference string that was saved before to the table.

Parameters:
table - the table
saveColumnName - true or false. Please always use the same value when you call getSortableTablePreference(SortableTable, boolean).
pref - the preference string. If the value is null or if the string is not saved from the table as specified in table parameter, this method will simply return and won't change the table at all.
Returns:
true if the preference is set correctly. Otherwise false.

synchronizeTableRowSelection

public static void synchronizeTableRowSelection(JTable[] tables)
Synchronizes the row selection of the tables so that if any rows in one table is selected, the same rows in all tables will be selected too.

Parameters:
tables - the tables

unsynchronizeTableRowSelection

public static void unsynchronizeTableRowSelection(JTable[] tables)
UnSynchronizes the row selection of the tables. This method is only useful if you called synchronizeTableRowSelection(javax.swing.JTable[]) earlier.

Parameters:
tables - the tables

unifyTableRowSelection

public static void unifyTableRowSelection(JTable[] tables)
Unifies the row selection into one selection so that only one row can be selected in all tables. You should call this method only when the table in tables array in row selection mode.

Internally it uses ListSelectionModelGroup to implement this feature.

Parameters:
tables - the tables

ununifyTableRowSelection

public static void ununifyTableRowSelection(JTable[] tables)
Reverts the unification of the row selection by unifyTableRowSelection(javax.swing.JTable[]). This method is only useful if you called unifyTableRowSelection(javax.swing.JTable[]) earlier.

Internally it uses ListSelectionModelGroup to implement this feature.

Parameters:
tables - the tables

unifyTableColumnSelection

public static void unifyTableColumnSelection(JTable[] tables)
Unifies the column selection into one selection so that only one column can be selected in all tables.

Internally it uses ListSelectionModelGroup to implement this feature.

Parameters:
tables - the tables

ununifyTableColumnSelection

public static void ununifyTableColumnSelection(JTable[] tables)
Reverts the unification of the column selection by unifyTableColumnSelection(javax.swing.JTable[]). This method is only useful if you called unifyTableColumnSelection(javax.swing.JTable[]) earlier.

Internally it uses ListSelectionModelGroup to implement this feature.

Parameters:
tables - the tables

unifyTableNonContiguousCellSelection

public static void unifyTableNonContiguousCellSelection(JTable[] tables)
Unifies the non-contiguous cell selection into one selection so that only one cell can be selected in all tables. You should call this method only when the table in tables array in non-contiguous cell selection mode.

Internally it uses TableSelectionModelGroup to implement this feature.

Parameters:
tables - the tables

ununifyTableNonContiguousCellSelection

public static void ununifyTableNonContiguousCellSelection(JTable[] tables)
Reverts the unification of the cell selection by unifyTableNonContiguousCellSelection(javax.swing.JTable[]). This method is only useful if you called unifyTableNonContiguousCellSelection(javax.swing.JTable[]) earlier.

Internally it uses TableSelectionModelGroup to implement this feature.

Parameters:
tables - the tables

unifyTableCellSelection

public static void unifyTableCellSelection(JTable[] tables)
Unifies the mixed cell selection into one selection so that only one cell can be selected in all tables. You could call this method when your tables have different cell selection options.

Internally it uses MixedTableSelectionModelGroup to implement this feature.

Parameters:
tables - the tables

unifyTableCellSelection

public static void unifyTableCellSelection(JTable[] tables,
                                           JTable stayTable)
Unifies the mixed cell selection into one selection so that only one cell can be selected in all tables. You could call this method when your tables have different cell selection options.

Internally it uses MixedTableSelectionModelGroup to implement this feature.

Parameters:
tables - the tables
stayTable - the table which will not clear its selection on other table's selection

ununifyTableCellSelection

public static void ununifyTableCellSelection(JTable[] tables)
Reverts the unification of the cell selection by unifyTableCellSelection(javax.swing.JTable[]). This method is only useful if you called unifyTableCellSelection(javax.swing.JTable[]) earlier.

Internally it uses MixedTableSelectionModelGroup to implement this feature.

Parameters:
tables - the tables

unifyTableCellEditing

public static void unifyTableCellEditing(JTable[] tables)
Unifies the column selection into one selection so that only one column can be selected in all tables. You should call this method only when the table in tables array in column selection mode.

Internally it uses ListSelectionModelGroup to implement this feature.

Parameters:
tables - the tables

ununifyTableCellEditing

public static void ununifyTableCellEditing(JTable[] tables)
Reverts the unification of the table celling by unifyTableCellEditing(javax.swing.JTable[]). This method is only useful if you called unifyTableCellEditing(javax.swing.JTable[]) earlier.

Parameters:
tables - the tables

synchronizeRowHeight

public static void synchronizeRowHeight(JTable[] tables)
Synchronizes the table height of the list of tables to be the same. Whenever one table's JTable.setRowHeight(int) method is called, the new height will be applied to all tables. This is only for when table rows have the same row height. If they have different row heights, you should use synchronizeRowHeights(JTable[]) to synchronize the row heights.

Parameters:
tables - the tables

synchronizeRowHeights

public static void synchronizeRowHeights(JTable[] tables)
Synchronizes the table row heights and table header height.

Even though the parameter is an array of regular JTable, the code actually requires an array of JideTable which provides additional features of row heights.

Parameters:
tables - the tables

synchronizeTableColumnSelection

public static void synchronizeTableColumnSelection(JTable master,
                                                   JTable slave)
Makes the master table and slave table using the same SelectionModel so that when any selection change in master table will be reflected in slave table too.

Parameters:
master - the master table
slave - the slave table

unsynchronizeTableColumnSelection

public static void unsynchronizeTableColumnSelection(JTable master,
                                                     JTable slave)
The reverse action of synchronizeTableColumnSelection(javax.swing.JTable, javax.swing.JTable).

Parameters:
master - the master table
slave - the slave table

synchronizeTables

public static void synchronizeTables(JTable[] tables)
Links the tables in the table array so that they look like one table. The things this method actually did is smoothing key navigation (tab or array key will navigate across the table, maintaining only one sorting column if those are SortableTable, synchronizing the row selection.

Parameters:
tables - the tables

synchronizeTables

public static void synchronizeTables(JTable[] tables,
                                     boolean rowSelectionAllowed,
                                     boolean columnSelectionAllowed)
Links the tables in the table array so that they look like one table. The things this method actually did is smoothing key navigation (tab or array key will navigate across the table, maintaining only one sorting column if those are SortableTable, synchronizing the row selection.

Parameters:
tables - the list of tables.
rowSelectionAllowed - whether row selection is allowed.
columnSelectionAllowed - whether column selection is allowed.

synchronizeTables

public static void synchronizeTables(JTable[] tables,
                                     boolean rowSelectionAllowed,
                                     boolean columnSelectionAllowed,
                                     boolean nonContiguousSelectionAllowed)
Links the tables in the table array so that they look like one table. The things this method actually did is smoothing key navigation (tab or array key will navigate across the table, maintaining only one sorting column if those are SortableTable, synchronizing the row selection.

Parameters:
tables - the tables
rowSelectionAllowed - true to allow the row selection. Otherwise false.
columnSelectionAllowed - true to allow the column selection. Otherwise false.
nonContiguousSelectionAllowed - true to allow the non-contiguous cell selection. Otherwise false.

synchronizeDropLocation

public static void synchronizeDropLocation(JTable[] tables)

synchronizeSorting

public static void synchronizeSorting(JTable[] tables)

synchronizeNavigationKeys

public static void synchronizeNavigationKeys(JTable[][] tables)
Synchronizes the navigation keys. The navigation keys include TAB, SHIFT-TAB, LEFT, RIGHT, UP, RIGHT. Basically if you press TAB key at the last column, the focus will change to the next table's first column of the same row.

Parameters:
tables - the tables

unsynchronizeNavigationKeys

public static void unsynchronizeNavigationKeys(JTable[][] tables)
Unsynchronizes the navigation keys. It basically undo the changes did by synchronizeNavigationKeys(javax.swing.JTable[]).

Parameters:
tables - the tables

synchronizeNavigationKeys

public static void synchronizeNavigationKeys(JTable[] tableArray)
Synchronizes the navigation keys. The navigation keys include TAB, SHIFT-TAB, LEFT, RIGHT. Basically if you press TAB key at the last column, the focus will change to the next table's first column of the same row.

Parameters:
tableArray - the tables

unsynchronizeNavigationKeys

public static void unsynchronizeNavigationKeys(JTable[] tables)
Unsynchronizes the navigation keys. It basically undo the changes did by synchronizeNavigationKeys(javax.swing.JTable[]).

Parameters:
tables - the tables

nextRow

protected static int nextRow(JTable table,
                             JTable nextTable)

previousRow

protected static int previousRow(JTable table,
                                 JTable prevTable)

synchronizeTableColumn

public static void synchronizeTableColumn(JTable master,
                                          JTable slave)
Synchronize two tables' columns so that the corresponding table column in both tables have the same width, at the same position. If column selection is enabled, they will have the same column selection.

Parameters:
master - the master table
slave - the slave table

synchronizeTableColumnWidth

public static void synchronizeTableColumnWidth(JTable[] tables)
Synchronize two tables' columns so that the corresponding table column in both tables have the same width, at the same position. If column selection is enabled, they will have the same column selection.

Parameters:
tables - all the tables that need to be synchronized.

unsynchronizeTableColumn

public static void unsynchronizeTableColumn(JTable master,
                                            JTable slave)
The reverse action of synchronizeTableColumn(javax.swing.JTable, javax.swing.JTable).

Parameters:
master - the master table
slave - the slave table

synchronizeTableColumnWidth

public static void synchronizeTableColumnWidth(JTable master,
                                               JTable slave)
Synchronize two tables' columns so that the corresponding table column in both tables have the same width. Different from synchronizeTableColumn(javax.swing.JTable, javax.swing.JTable), this method only synchronizes the two tables' width and their columns width.

Parameters:
master - the master table
slave - the slave table

synchronizeTableAndColumnsWidth

public static void synchronizeTableAndColumnsWidth(JTable master,
                                                   JTable slave)
Synchronizes the two table columns width as well as the whole table width. It assumes the two tables have the same number of columns. This method will only synchronize the two tables' width and columns' width once. If the width of master table changes after this method is called, the slave table will not change. If you want the two tables to be always synchronized, you can use synchronizeTableColumnWidth(javax.swing.JTable, javax.swing.JTable) method.

Parameters:
master - the master table
slave - the slave table

synchronizeTableColumnWidthNow

public static void synchronizeTableColumnWidthNow(JTable master,
                                                  JTable slave)

getAutoResizeExtraWidth

public static int getAutoResizeExtraWidth()
Gets the value of extra width we will add to calculated column width when we do autoResizeAllColumns(javax.swing.JTable) or autoResizeColumn(javax.swing.JTable, int). Default is 4.

Returns:
extra width when we auto-resize table column.

setAutoResizeExtraWidth

public static void setAutoResizeExtraWidth(int autoResizeExtraWidth)
We will add 4 pixels extra width to the calculated column width when we do autoResizeAllColumns(javax.swing.JTable) or autoResizeColumn(javax.swing.JTable, int). You can change this field to a different value if you want a different extra width.

Parameters:
autoResizeExtraWidth - the extra width added to the calculated preferred width.

autoResizeColumn

public static int autoResizeColumn(JTable table,
                                   int col)
Resizes the optimal width for the column of the given table. The calculation is based on the preferred width of the header and cell renderer.

By default, it will consider header column width. If you don't want, you can either use autoResizeColumn(javax.swing.JTable, int, boolean) method or you can call table.putClientProperty(TableUtils.AUTO_RESIZE_CONSIDER_HEADER, Boolean.FALSE).

Taken from the newsgroup de.comp.lang.java with some modifications.

Note, this method will only work after the table is visible.

ColumnIdentifierTableModel will be considered first. If there is a ColumnIdentifierTableModel, it will take the preferred size from that model directly.

Parameters:
table - the table to calculate the column width
col - the column to calculate the widths
Returns:
the preferred width it sets to the column. -1 if the preferred width is not changed.

autoResizeColumn

public static int autoResizeColumn(JTable table,
                                   int col,
                                   boolean considerHeader)
Resizes the optimal width for the column of the given table. The calculation is based on the preferred width of the header (optional) and cell renderer.
Taken from the newsgroup de.comp.lang.java with some modifications.

Note, this method will only work after the table is visible.

ColumnIdentifierTableModel will be considered first. If there is a ColumnIdentifierTableModel, it will take the preferred size from that model directly.

Parameters:
table - the table to calculate the column width
col - the column to calculate the widths
considerHeader - if considering header column width when calculating the optimal width. Please note, for the NestedTableHeader, only the last row in the table header can be considered.
Returns:
the preferred width it sets to the column. -1 if the preferred width is not changed.

autoResizeColumn

public static int autoResizeColumn(JTable table,
                                   int col,
                                   boolean considerHeader,
                                   boolean visibleRowsOnly)
Resizes the optimal width for the column of the given table. The calculation is based on the preferred width of the header (optional) and cell renderer.
Taken from the newsgroup de.comp.lang.java with some modifications.

Note, this method will only work after the table is visible.

ColumnIdentifierTableModel will be considered first. If there is a ColumnIdentifierTableModel, it will take the preferred size from that model directly.

Parameters:
table - the table to calculate the column width
col - the column to calculate the widths
considerHeader - if considering header column width when calculating the optimal width. Please note, for the NestedTableHeader, only the last row in the table header can be considered.
visibleRowsOnly - if we only consider the visible rows width only when calculating the preferred width.
Returns:
the preferred width it sets to the column. -1 if the preferred width is not changed.

autoResizeColumn

public static int autoResizeColumn(JTable table,
                                   int col,
                                   boolean considerHeader,
                                   boolean visibleRowsOnly,
                                   int minimumWidth)
Resizes the optimal width for the column of the given table. The calculation is based on the preferred width of the header (optional) and cell renderer.
Taken from the newsgroup de.comp.lang.java with some modifications.

Note, this method will only work after the table is visible.

ColumnIdentifierTableModel will be considered first. If there is a ColumnIdentifierTableModel, it will take the preferred size from that model directly.

Parameters:
table - the table to calculate the column width
col - the column to calculate the widths
considerHeader - if considering header column width when calculating the optimal width. Please note, for the NestedTableHeader, only the last row in the table header can be considered.
visibleRowsOnly - if we only consider the visible rows width only when calculating the preferred width.
minimumWidth - the minimum width of the column after resizing. -1 if there is no minimum width.
Returns:
the preferred width it sets to the column. -1 if the preferred width is not changed.

autoResizeColumn

public static int autoResizeColumn(JTable table,
                                   int col,
                                   boolean considerHeader,
                                   boolean visibleRowsOnly,
                                   int minimumWidth,
                                   int maximumWidth)
Resizes the optimal width for the column of the given table. The calculation is based on the preferred width of the header (optional) and cell renderer.
Taken from the newsgroup de.comp.lang.java with some modifications.

Note, this method will only work after the table is visible.

Parameters:
table - the table to calculate the column width
col - the column to calculate the widths
considerHeader - if considering header column width when calculating the optimal width. Please note, for the NestedTableHeader, only the last row in the table header can be considered.
visibleRowsOnly - if we only consider the visible rows width only when calculating the preferred width.
minimumWidth - the minimum width of the column after resizing. -1 if there is no minimum width.
maximumWidth - the maximum width of the column after resizing. -1 if there is no maximum width.
Returns:
the preferred width it sets to the column. -1 if the preferred width is not changed.

autoResizeColumn

public static int autoResizeColumn(JTable table,
                                   int col,
                                   boolean considerHeader,
                                   boolean visibleRowsOnly,
                                   int minimumWidth,
                                   int maximumWidth,
                                   boolean highPerformance)
Resizes the optimal width for the column of the given table. The calculation is based on the preferred width of the header (optional) and cell renderer.
Taken from the newsgroup de.comp.lang.java with some modifications.

Note, this method will only work after the table is visible.

ColumnIdentifierTableModel will be considered first. If there is a ColumnIdentifierTableModel, it will take the preferred size from that model directly.

Parameters:
table - the table to calculate the column width
col - the column to calculate the widths
considerHeader - if considering header column width when calculating the optimal width. Please note, for the NestedTableHeader, only the last row in the table header can be considered.
visibleRowsOnly - if we only consider the visible rows width only when calculating the preferred width.
minimumWidth - the minimum width of the column after resizing. -1 if there is no minimum width.
maximumWidth - the maximum width of the column after resizing. -1 if there is no maximum width.
highPerformance - if the calculation only get cell renderer once to check the longest string. This way will have higher performance but may not be super accurate if you have different fonts in different rows.
Returns:
the preferred width it sets to the column. -1 if the preferred width is not changed.
Since:
3.1.1

autoResizeColumn

public static int autoResizeColumn(JTable table,
                                   int col,
                                   boolean considerHeader,
                                   boolean visibleRowsOnly,
                                   int minimumWidth,
                                   int maximumWidth,
                                   boolean highPerformance,
                                   boolean respectColumnWidthTableModel)
Resizes the optimal width for the column of the given table. The calculation is based on the preferred width of the header (optional) and cell renderer.
Taken from the newsgroup de.comp.lang.java with some modifications.

Note, this method will only work after the table is visible.

ColumnIdentifierTableModel will be considered first. If there is a ColumnIdentifierTableModel, it will take the preferred size from that model directly.

Parameters:
table - the table to calculate the column width
col - the column to calculate the widths
considerHeader - if considering header column width when calculating the optimal width. Please note, for the NestedTableHeader, only the last row in the table header can be considered.
visibleRowsOnly - if we only consider the visible rows width only when calculating the preferred width.
minimumWidth - the minimum width of the column after resizing. -1 if there is no minimum width.
maximumWidth - the maximum width of the column after resizing. -1 if there is no maximum width.
highPerformance - if the calculation only get cell renderer once to check the longest string. This way will have higher performance but may not be super accurate if you have different fonts in different rows.
respectColumnWidthTableModel - if the calculation will get the preferred width without calculation if there is a ColumnWidthTableModel in place.
Returns:
the preferred width it sets to the column. -1 if the preferred width is not changed.
Since:
3.2.4

autoResizeAllColumns

public static int[] autoResizeAllColumns(JTable table)
Resizes the optimal width for all columns of the given table. The calculation is based on the preferred width of the header and cell renderer. In order to make this method working correctly, you also need to call JTable.setAutoResizeMode(int) and set it to JTable.AUTO_RESIZE_OFF.
Taken from the newsgroup de.comp.lang.java with some modifications.

autoResizeAllColumns will calculate the width of each column first then resize the table using SwingUtlities.invokeLater if the calling thread is not EDT. So this method is Swing thread safe. Because of this feature, when this method returns while the calling thread is not EDT, you cannot assume the table columns are all correctly resized (as it depends on when SwingUtlities.invokeLater actually calls). However the returned int array will tell you the width of all columns after they are resized.

ColumnIdentifierTableModel will be considered first. If there is a ColumnIdentifierTableModel, it will take the preferred size from that model directly.

Parameters:
table - the table to calculate the column widths
Returns:
the resized table column width as an int array.

autoResizeAllColumns

public static int[] autoResizeAllColumns(JTable table,
                                         boolean considerHeader)
Resizes the optimal width for all columns of the given table. The calculation is based on the preferred width of the header and cell renderer. In order to make this method working correctly, you also need to call JTable.setAutoResizeMode(int) and set it to JTable.AUTO_RESIZE_OFF.
Taken from the newsgroup de.comp.lang.java with some modifications.

autoResizeAllColumns will calculate the width of each column first then resize the table using SwingUtlities.invokeLater if the calling thread is not EDT. So this method is Swing thread safe. Because of this feature, when this method returns while the calling thread is not EDT, you cannot assume the table columns are all correctly resized (as it depends on when SwingUtlities.invokeLater actually calls). However the returned int array will tell you the width of all columns after they are resized.

ColumnIdentifierTableModel will be considered first. If there is a ColumnIdentifierTableModel, it will take the preferred size from that model directly.

Parameters:
table - the table to calculate the column widths
considerHeader - if considering header column width when calculating the optimal width. Please note, for the NestedTableHeader, only the last row in the table header can be considered.
Returns:
the resized table column width as an int array.

autoResizeAllColumns

public static int[] autoResizeAllColumns(JTable table,
                                         int[] minimumWidth,
                                         boolean considerHeader)
Resizes the optimal width for all columns of the given table. The calculation is based on the preferred width of the header and cell renderer. In order to make this method working correctly, you also need to call JTable.setAutoResizeMode(int) and set it to JTable.AUTO_RESIZE_OFF.
Taken from the newsgroup de.comp.lang.java with some modifications.

autoResizeAllColumns will calculate the width of each column first then resize the table using SwingUtlities.invokeLater if the calling thread is not EDT. So this method is Swing thread safe. Because of this feature, when this method returns while the calling thread is not EDT, you cannot assume the table columns are all correctly resized (as it depends on when SwingUtlities.invokeLater actually calls). However the returned int array will tell you the width of all columns after they are resized.

ColumnIdentifierTableModel will be considered first. If there is a ColumnIdentifierTableModel, it will take the preferred size from that model directly.

Parameters:
table - the table to calculate the column widths
minimumWidth - the minimum width of each column. It could be either null or the same length as the table column count.
considerHeader - if considering header column width when calculating the optimal width. Please note, for the NestedTableHeader, only the last row in the table header can be considered.
Returns:
the resized table column width as an int array.

autoResizeAllColumns

public static int[] autoResizeAllColumns(JTable table,
                                         int[] minimumWidth,
                                         boolean considerHeader,
                                         boolean visibleRowsOnly)
Resizes the optimal width for all columns of the given table. The calculation is based on the preferred width of the header and cell renderer. In order to make this method working correctly, you also need to call JTable.setAutoResizeMode(int) and set it to JTable.AUTO_RESIZE_OFF.
Taken from the newsgroup de.comp.lang.java with some modifications.

autoResizeAllColumns will calculate the width of each column first then resize the table using SwingUtlities.invokeLater if the calling thread is not EDT. So this method is Swing thread safe. Because of this feature, when this method returns while the calling thread is not EDT, you cannot assume the table columns are all correctly resized (as it depends on when SwingUtlities.invokeLater actually calls). However the returned int array will tell you the width of all columns after they are resized.

ColumnIdentifierTableModel will be considered first. If there is a ColumnIdentifierTableModel, it will take the preferred size from that model directly.

Parameters:
table - the table to calculate the column widths
minimumWidth - the minimum width of each column. It could be either null or the same length as the table column count.
considerHeader - if considering header column width when calculating the optimal width. Please note, for the NestedTableHeader, only the last row in the table header can be considered.
visibleRowsOnly - if we only consider the visible rows width only when calculating the preferred width.
Returns:
the resized table column width as an int array.

autoResizeAllColumns

public static int[] autoResizeAllColumns(JTable table,
                                         int[] minimumWidth,
                                         int[] maximumWidth,
                                         boolean considerHeader,
                                         boolean visibleRowsOnly)
Resizes the optimal width for all columns of the given table. The calculation is based on the preferred width of the header and cell renderer. In order to make this method working correctly, you also need to call JTable.setAutoResizeMode(int) and set it to JTable.AUTO_RESIZE_OFF.
Taken from the newsgroup de.comp.lang.java with some modifications.

autoResizeAllColumns will calculate the width of each column first then resize the table using SwingUtlities.invokeLater if the calling thread is not EDT. So this method is Swing thread safe. Because of this feature, when this method returns while the calling thread is not EDT, you cannot assume the table columns are all correctly resized (as it depends on when SwingUtlities.invokeLater actually calls). However the returned int array will tell you the width of all columns after they are resized.

ColumnIdentifierTableModel will be considered first. If there is a ColumnIdentifierTableModel, it will take the preferred size from that model directly.

Parameters:
table - the table to calculate the column widths
minimumWidth - the minimum width of each column. It could be either null or the same length as the table column count.
maximumWidth - the maximum width of each column. It could be either null or the same length as the table column count.
considerHeader - if considering header column width when calculating the optimal width. Please note, for the NestedTableHeader, only the last row in the table header can be considered.
visibleRowsOnly - if we only consider the visible rows width only when calculating the preferred width.
Returns:
the resized table column width as an int array.

autoResizeAllColumns

public static int[] autoResizeAllColumns(JTable table,
                                         int[] minimumWidth,
                                         int[] maximumWidth,
                                         boolean considerHeader,
                                         boolean visibleRowsOnly,
                                         boolean highPerformance)
Resizes the optimal width for all columns of the given table. The calculation is based on the preferred width of the header and cell renderer. In order to make this method working correctly, you also need to call JTable.setAutoResizeMode(int) and set it to JTable.AUTO_RESIZE_OFF.
Taken from the newsgroup de.comp.lang.java with some modifications.

autoResizeAllColumns will calculate the width of each column first then resize the table using SwingUtlities.invokeLater if the calling thread is not EDT. So this method is Swing thread safe. Because of this feature, when this method returns while the calling thread is not EDT, you cannot assume the table columns are all correctly resized (as it depends on when SwingUtlities.invokeLater actually calls). However the returned int array will tell you the width of all columns after they are resized.

ColumnIdentifierTableModel will be considered first. If there is a ColumnIdentifierTableModel, it will take the preferred size from that model directly.

Parameters:
table - the table to calculate the column widths
minimumWidth - the minimum width of each column. It could be either null or the same length as the table column count.
maximumWidth - the maximum width of each column. It could be either null or the same length as the table column count.
considerHeader - if considering header column width when calculating the optimal width. Please note, for the NestedTableHeader, only the last row in the table header can be considered.
visibleRowsOnly - if we only consider the visible rows width only when calculating the preferred width.
highPerformance - if the calculation only get cell renderer once to check the longest string. This way will have higher performance but may not be super accurate if you have different fonts in different rows.
Returns:
the resized table column width as an int array.
Since:
3.1.1

autoResizeAllColumns

public static int[] autoResizeAllColumns(JTable table,
                                         int[] minimumWidth,
                                         int[] maximumWidth,
                                         boolean considerHeader,
                                         boolean visibleRowsOnly,
                                         boolean highPerformance,
                                         boolean respectColumnWidthTableModel)
Resizes the optimal width for all columns of the given table. The calculation is based on the preferred width of the header and cell renderer. In order to make this method working correctly, you also need to call JTable.setAutoResizeMode(int) and set it to JTable.AUTO_RESIZE_OFF.
Taken from the newsgroup de.comp.lang.java with some modifications.

autoResizeAllColumns will calculate the width of each column first then resize the table using SwingUtlities.invokeLater if the calling thread is not EDT. So this method is Swing thread safe. Because of this feature, when this method returns while the calling thread is not EDT, you cannot assume the table columns are all correctly resized (as it depends on when SwingUtlities.invokeLater actually calls). However the returned int array will tell you the width of all columns after they are resized.

ColumnIdentifierTableModel will be considered first. If there is a ColumnIdentifierTableModel, it will take the preferred size from that model directly.

Parameters:
table - the table to calculate the column widths
minimumWidth - the minimum width of each column. It could be either null or the same length as the table column count.
maximumWidth - the maximum width of each column. It could be either null or the same length as the table column count.
considerHeader - if considering header column width when calculating the optimal width. Please note, for the NestedTableHeader, only the last row in the table header can be considered.
visibleRowsOnly - if we only consider the visible rows width only when calculating the preferred width.
highPerformance - if the calculation only get cell renderer once to check the longest string. This way will have higher performance but may not be super accurate if you have different fonts in different rows.
respectColumnWidthTableModel - if the calculation will get the preferred width without calculation if there is a ColumnWidthTableModel in place.
Returns:
the resized table column width as an int array.
Since:
3.2.4

isTableColumnResizable

public static boolean isTableColumnResizable(JTable table,
                                             TableColumn column)
Checks if the table column is resizable. It is resizable only when table header allows resizing and the column getResizable() return true. If table header is null, as long as the column is resizable, it will return true.

Parameters:
table - the table
column - the column index.
Returns:
true if the column can be resized.

autoResizeRow

public static int autoResizeRow(JTable table,
                                int row)
Calculates the optimal height for the row of the given table.

Parameters:
table - the table to calculate the row height
row - the row to calculate the height
Returns:
the preferred height of this row

autoResizeRow

public static int autoResizeRow(JTable table,
                                int row,
                                int minimumHeight)
Calculates the optimal height for the row of the given table.

Parameters:
table - the table to calculate the row height
row - the row to calculate the height
minimumHeight - the minimum height of the row after resizing. -1 if there is no minimum height.
Returns:
the preferred height of this row

autoResizeRows

public static int[] autoResizeRows(JTable table,
                                   int fromRow,
                                   int toRow)
Calculates the optimal height for the rows of the given table.

autoResizeAllRows will calculate the height of each row first then resize the table using SwingUtlities.invokeLater if the calling thread is not EDT. So this method is Swing thread safe. Because of this feature, when this method returns while the calling thread is not EDT, you cannot assume the table rows are all correctly resized (as it depends on when SwingUtlities.invokeLater actually calls). However the returned int array will tell you the height of all rows after they are resized.

Parameters:
table - the table to calculate the row heights
fromRow - the beginning row to auto resize
toRow - the end row to auto resize
Returns:
the row heights array after resize.

autoResizeRows

public static int[] autoResizeRows(JTable table,
                                   int fromRow,
                                   int toRow,
                                   int[] minimumHeight)
Calculates the optimal height for the rows of the given table.

autoResizeAllRows will calculate the height of each row first then resize the table using SwingUtlities.invokeLater if the calling thread is not EDT. So this method is Swing thread safe. Because of this feature, when this method returns while the calling thread is not EDT, you cannot assume the table rows are all correctly resized (as it depends on when SwingUtlities.invokeLater actually calls). However the returned int array will tell you the height of all rows after they are resized.

Parameters:
table - the table to calculate the row heights
fromRow - the beginning row to auto resize
toRow - the end row to auto resize
minimumHeight - the minimum height of each row. It could be either null or the same length as the table row count.
Returns:
the row heights array after resize.

autoResizeAllRows

public static int[] autoResizeAllRows(JTable table)
Calculates the optimal height for the row of the given table.

autoResizeAllRows will calculate the height of each row first then resize the table using SwingUtlities.invokeLater if the calling thread is not EDT. So this method is Swing thread safe. Because of this feature, when this method returns while the calling thread is not EDT, you cannot assume the table rows are all correctly resized (as it depends on when SwingUtlities.invokeLater actually calls). However the returned int array will tell you the height of all rows after they are resized.

Parameters:
table - the table to calculate the row heights
Returns:
the row heights array after resize.

autoResizeAllRows

public static int[] autoResizeAllRows(JTable table,
                                      int[] minimumHeight)
Calculates the optimal height for the row of the given table.

autoResizeAllRows will calculate the height of each row first then resize the table using SwingUtlities.invokeLater if the calling thread is not EDT. So this method is Swing thread safe. Because of this feature, when this method returns while the calling thread is not EDT, you cannot assume the table rows are all correctly resized (as it depends on when SwingUtlities.invokeLater actually calls). However the returned int array will tell you the height of all rows after they are resized.

Parameters:
table - the table to calculate the row heights
minimumHeight - the minimum height of each row. It could be either null or the same length as the table row count.
Returns:
the row heights array after resize.

calculateRowHeight

protected static int calculateRowHeight(JTable table,
                                        int row,
                                        int minimumHeight)

stopCellEditingForAll

public static boolean stopCellEditingForAll(JTable table)
Stops editing for the table, including all tables in the same TableScrollPane.

Parameters:
table - the table
Returns:
true if editing stopped successfully. Otherwise false.
Since:
3.3.1

ensureRowSelectionVisible

public static void ensureRowSelectionVisible(JTable table)
To make sure the selected row is visible. If there are multiple selections, it will try to make the as many selections visible as possible.

Parameters:
table - the table

ensureRowVisible

public static void ensureRowVisible(JTable table,
                                    int row)
To make sure the row is visible. If the table's horizontal scroll bar is visible, the method will not change the horizontal scroll bar's position.

Parameters:
table - the table
row - the row index

findColumnIndex

public static int findColumnIndex(TableModel model,
                                  String columnName)
Finds the column that has the columnName.

Parameters:
model - the table model.
columnName - the column name
Returns:
the column index of the column that has the columnName. -1 if columnName is null or not found.

findColumnIndexes

public static int[] findColumnIndexes(TableModel model,
                                      String[] columnNames)
Finds the column indexes that has the name specified in the columnNames array.

Parameters:
model - the table model
columnNames - column names array
Returns:
the column index array of the columns that have the columnName. Null if columnNames is null. -1 in the returned array if the column name is not found.

getViewPositionForRow

public static int getViewPositionForRow(JTable table,
                                        int row)
Gets the view y position for the row in a table.

Parameters:
table - the table.
row - the row index.
Returns:
the y position of the row.

setViewPositionForRow

public static void setViewPositionForRow(JTable table,
                                         int row,
                                         int position)
Sets the view y position for the row in a table.

Parameters:
table - the table.
row - the row index.
position - the y position.

saveColumnOrders

public static void saveColumnOrders(JTable table,
                                    boolean isUngroup)

clearColumnOrdersMemory

public static void clearColumnOrdersMemory(JTable table)

saveDefaultColumnOrders

public static void saveDefaultColumnOrders(TableScrollPane pane,
                                           TableModel model)

saveDefaultColumnOrders

public static void saveDefaultColumnOrders(GroupTable table)

saveColumnOrders

public static void saveColumnOrders(TableScrollPane pane)

clearColumnOrdersMemory

public static void clearColumnOrdersMemory(TableScrollPane pane)

getResizingColumn

public static TableColumn getResizingColumn(JTable table,
                                            Point p,
                                            int column)
Get the resizing column instance based on the table and point and the column.

Parameters:
table - the resizing JTable
p - the point of the mouse event
column - the column
Returns:
the resizing TableColumn instance. null if no instance found.

JIDE 3.5.15