|
JIDE 3.5.15 | ||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object com.jidesoft.grid.TableUtils
public class TableUtils
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 |
---|
public static final String CLIENT_PROPERTY_AUTO_RESIZE_CONSIDER_HEADER
public static final String CLIENT_PROPERTY_AUTO_RESIZE_CONSIDER_VISIBLE_ROWS_ONLY
public static final String CLIENT_PROPERTY_AUTO_RESIZE_HIGH_PERFORMANCE
public static final String CLIENT_PROPERTY_AUTO_RESIZE_RESPECT_COLUMN_WIDTH_TABLE_MODEL
public static final String CLIENT_PROPERTY_SAME_RENDERER_FOR_COLUMN
public static final String CLIENT_PROPERTY_TABLE_COLUMN_SNAPSHOT
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);
public static final String COLUMN_PROPERTY_HEADER_TABLE_MODEL_COLUMNS
public static final String COLUMN_PROPERTY_DATA_TABLE_MODEL_COLUMNS
public static final String COLUMN_PROPERTY_GROUP_TABLE_COUNT_COLUMN
public static final String COLUMN_PROPERTY_GROUP_TABLE_SEPARATE_GROUP_COLUMN
public static final char SEPARATOR
Constructor Detail |
---|
public TableUtils()
Method Detail |
---|
public static int[] saveRowHeights(JTable table)
table
- the table to save row heights
public static Map<Row,Integer> saveTreeTableRowHeights(TreeTable table)
table
- the tree table to save row heights
public static void loadTreeTableRowHeights(TreeTable table, Map<Row,Integer> rowHeightsMap)
table
- the tree table to be loadedrowHeightsMap
- saved row heights map by saveTreeTableRowHeights(TreeTable)
saveTreeTableRowHeights(TreeTable)
public static void loadRowHeights(JTable table, int[] rowHeights)
table
- the table to be loadedrowHeights
- saved row heights by saveRowHeights(javax.swing.JTable)
saveRowHeights(javax.swing.JTable)
public static int[] saveSelection(JTable table)
table
- the table
public static void loadSelection(JTable table, int[] selected)
loadSelection(javax.swing.JTable, int[], boolean)
with the scrollSelectionToVisible
set to
JComponent.getAutoscrolls()
.
table
- the tableselected
- an int array created by saveSelectionpublic static void loadSelection(JTable table, int[] selected, boolean scrollSelectionToVisible)
table
- the tableselected
- an int array created by saveSelectionscrollSelectionToVisible
- if the table is row selection mode and this flag is true, this method will scroll
the selected rows to visible.public static Row[] saveSelection(TreeTable table)
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.
table
- the table
loadSelection(TreeTable, Row[])
public static void loadSelection(TreeTable table, Row[] selectedRows)
saveSelection(TreeTable)
.
table
- the tree tableselectedRows
- a Row array created by saveSelectionpublic static void loadSelection(TreeTable table, Row[] selectedRows, boolean scrollSelectionToVisible)
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.
table
- the tree tableselectedRows
- a Row array created by saveSelectionscrollSelectionToVisible
- if the table is row selection mode and this flag is true, this method will scroll
the selected rows to visible.public static void loadSelection(TreeTable table, Row[] selectedRows, boolean scrollSelectionToVisible, boolean compareCurrentSelection)
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.
table
- the tree tableselectedRows
- a Row array created by saveSelectionscrollSelectionToVisible
- 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.public static Object eraseIdentifierFlag(Object identifier, String flag)
public static String getTablePreferenceByName(JTable table)
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.
table
- the table
public static String getTablePreferenceByName(TableScrollPane pane)
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.
pane
- the table scroll pane
public static boolean setTablePreferenceByName(JTable table, String pref)
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)
.
table
- the tablepref
- 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.
public static boolean setTablePreferenceByName(JTable table, String pref, boolean respectColumnModel)
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)
.
table
- the tablepref
- 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.
public static boolean setTablePreferenceByName(JTable table, String pref, boolean respectColumnModel, boolean hideNewColumnsInModel)
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.
table
- the tablepref
- 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.
public static boolean setTablePreferenceByName(TableScrollPane pane, String pref)
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.
pane
- the table scroll panepref
- 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.
public static boolean setTablePreferenceByName(TableScrollPane pane, String pref, boolean respectColumnModel)
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.
pane
- the table scroll panepref
- 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.
public static boolean setTablePreferenceByName(TableScrollPane pane, String pref, boolean respectColumnModel, boolean hideNewColumnsInModel)
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.
pane
- the table scroll panepref
- 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.
public static void adjustColumnOrderAndWidth(JTable table, Map<String,Integer> columnIndexMap, com.jidesoft.grid.TableColumnSnapshot snapshot, String[] values, int columnCount, boolean respectColumnModel, boolean hideNewColumnsInModel)
table
- the tablecolumnIndexMap
- column index mapsnapshot
- column order snapshotvalues
- saved column width valuescolumnCount
- saved column countrespectColumnModel
- a flaghideNewColumnsInModel
- a flagpublic static void adjustColumnOrderAndWidth(TableScrollPane pane, Map<String,Integer> columnIndexMap, com.jidesoft.grid.TableColumnSnapshot snapshot, String[] values, int columnCount, boolean respectColumnModel, boolean hideNewColumnsInModel)
pane
- table scroll panecolumnIndexMap
- column index mapsnapshot
- column order snapshotvalues
- saved column width valuescolumnCount
- saved column countrespectColumnModel
- the flaghideNewColumnsInModel
- a flagpublic static boolean setTableColumnWidthByName(JTable table, String pref)
getTablePreferenceByName(javax.swing.JTable)
. Different from setTablePreferenceByName(javax.swing.JTable, String)
, this method only restores the column width but not the
column order.
table
- the tablepref
- 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.
public static boolean setTableColumnWidthByName(TableScrollPane pane, String pref)
getTablePreferenceByName(TableScrollPane)
. Different from setTablePreferenceByName(TableScrollPane, String)
, this method only restores the column width but not the
column order.
pane
- the table scroll panepref
- 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.
@Deprecated public static String getTablePreference(JTable table)
getTablePreferenceByName(javax.swing.JTable)
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.
table
- the table
@Deprecated public static boolean setTablePreference(JTable table, String pref)
setTablePreferenceByName(javax.swing.JTable, String)
table
- the tablepref
- 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.
public static String getFilterableTableModelPreference(IFilterableTableModel model)
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.
model
- the IFilterableTableModel
public static boolean setFilterableTableModelPreference(IFilterableTableModel model, String pref)
model
- the IFilterableTableModelpref
- the preference string
getFilterableTableModelPreference(IFilterableTableModel)
public static String getSortableTablePreference(SortableTable table)
table
- the table
public static String getSortableTablePreference(SortableTable table, boolean saveColumName)
table
- the tablesaveColumName
- 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.
public static boolean setSortableTablePreference(SortableTable table, String pref)
table
- the tablepref
- 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.
public static boolean setSortableTablePreference(SortableTable table, String pref, boolean saveColumnName)
table
- the tablesaveColumnName
- 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.
public static void synchronizeTableRowSelection(JTable[] tables)
tables
- the tablespublic static void unsynchronizeTableRowSelection(JTable[] tables)
synchronizeTableRowSelection(javax.swing.JTable[])
earlier.
tables
- the tablespublic static void unifyTableRowSelection(JTable[] tables)
ListSelectionModelGroup
to implement this feature.
tables
- the tablespublic static void ununifyTableRowSelection(JTable[] tables)
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.
tables
- the tablespublic static void unifyTableColumnSelection(JTable[] tables)
ListSelectionModelGroup
to implement this feature.
tables
- the tablespublic static void ununifyTableColumnSelection(JTable[] tables)
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.
tables
- the tablespublic static void unifyTableNonContiguousCellSelection(JTable[] tables)
TableSelectionModelGroup
to implement this feature.
tables
- the tablespublic static void ununifyTableNonContiguousCellSelection(JTable[] tables)
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.
tables
- the tablespublic static void unifyTableCellSelection(JTable[] tables)
MixedTableSelectionModelGroup
to implement this feature.
tables
- the tablespublic static void unifyTableCellSelection(JTable[] tables, JTable stayTable)
MixedTableSelectionModelGroup
to implement this feature.
tables
- the tablesstayTable
- the table which will not clear its selection on other table's selectionpublic static void ununifyTableCellSelection(JTable[] tables)
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.
tables
- the tablespublic static void unifyTableCellEditing(JTable[] tables)
ListSelectionModelGroup
to implement this feature.
tables
- the tablespublic static void ununifyTableCellEditing(JTable[] tables)
unifyTableCellEditing(javax.swing.JTable[])
. This method
is only useful if you called unifyTableCellEditing(javax.swing.JTable[])
earlier.
tables
- the tablespublic static void synchronizeRowHeight(JTable[] tables)
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.
tables
- the tablespublic static void synchronizeRowHeights(JTable[] tables)
tables
- the tablespublic static void synchronizeTableColumnSelection(JTable master, JTable slave)
master
- the master tableslave
- the slave tablepublic static void unsynchronizeTableColumnSelection(JTable master, JTable slave)
synchronizeTableColumnSelection(javax.swing.JTable, javax.swing.JTable)
.
master
- the master tableslave
- the slave tablepublic static void synchronizeTables(JTable[] tables)
tables
- the tablespublic static void synchronizeTables(JTable[] tables, boolean rowSelectionAllowed, boolean columnSelectionAllowed)
tables
- the list of tables.rowSelectionAllowed
- whether row selection is allowed.columnSelectionAllowed
- whether column selection is allowed.public static void synchronizeTables(JTable[] tables, boolean rowSelectionAllowed, boolean columnSelectionAllowed, boolean nonContiguousSelectionAllowed)
tables
- the tablesrowSelectionAllowed
- 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.public static void synchronizeDropLocation(JTable[] tables)
public static void synchronizeSorting(JTable[] tables)
public static void synchronizeNavigationKeys(JTable[][] tables)
tables
- the tablespublic static void unsynchronizeNavigationKeys(JTable[][] tables)
synchronizeNavigationKeys(javax.swing.JTable[])
.
tables
- the tablespublic static void synchronizeNavigationKeys(JTable[] tableArray)
tableArray
- the tablespublic static void unsynchronizeNavigationKeys(JTable[] tables)
synchronizeNavigationKeys(javax.swing.JTable[])
.
tables
- the tablesprotected static int nextRow(JTable table, JTable nextTable)
protected static int previousRow(JTable table, JTable prevTable)
public static void synchronizeTableColumn(JTable master, JTable slave)
master
- the master tableslave
- the slave tablepublic static void synchronizeTableColumnWidth(JTable[] tables)
tables
- all the tables that need to be synchronized.public static void unsynchronizeTableColumn(JTable master, JTable slave)
synchronizeTableColumn(javax.swing.JTable, javax.swing.JTable)
.
master
- the master tableslave
- the slave tablepublic static void synchronizeTableColumnWidth(JTable master, JTable slave)
synchronizeTableColumn(javax.swing.JTable, javax.swing.JTable)
, this method only
synchronizes the two tables' width and their columns width.
master
- the master tableslave
- the slave tablepublic static void synchronizeTableAndColumnsWidth(JTable master, JTable slave)
synchronizeTableColumnWidth(javax.swing.JTable,
javax.swing.JTable)
method.
master
- the master tableslave
- the slave tablepublic static void synchronizeTableColumnWidthNow(JTable master, JTable slave)
public static int getAutoResizeExtraWidth()
autoResizeAllColumns(javax.swing.JTable)
or autoResizeColumn(javax.swing.JTable, int)
. Default is 4.
public static void setAutoResizeExtraWidth(int autoResizeExtraWidth)
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.
autoResizeExtraWidth
- the extra width added to the calculated preferred width.public static int autoResizeColumn(JTable table, int col)
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.
table
- the table to calculate the column widthcol
- the column to calculate the widths
public static int autoResizeColumn(JTable table, int col, boolean considerHeader)
ColumnIdentifierTableModel
will be considered first. If there is a ColumnIdentifierTableModel, it will
take the preferred size from that model directly.
table
- the table to calculate the column widthcol
- the column to calculate the widthsconsiderHeader
- 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.
public static int autoResizeColumn(JTable table, int col, boolean considerHeader, boolean visibleRowsOnly)
ColumnIdentifierTableModel
will be considered first. If there is a ColumnIdentifierTableModel, it will
take the preferred size from that model directly.
table
- the table to calculate the column widthcol
- the column to calculate the widthsconsiderHeader
- 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.
public static int autoResizeColumn(JTable table, int col, boolean considerHeader, boolean visibleRowsOnly, int minimumWidth)
ColumnIdentifierTableModel
will be considered first. If there is a ColumnIdentifierTableModel, it will
take the preferred size from that model directly.
table
- the table to calculate the column widthcol
- the column to calculate the widthsconsiderHeader
- 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.
public static int autoResizeColumn(JTable table, int col, boolean considerHeader, boolean visibleRowsOnly, int minimumWidth, int maximumWidth)
table
- the table to calculate the column widthcol
- the column to calculate the widthsconsiderHeader
- 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.
public static int autoResizeColumn(JTable table, int col, boolean considerHeader, boolean visibleRowsOnly, int minimumWidth, int maximumWidth, boolean highPerformance)
ColumnIdentifierTableModel
will be considered first. If there is a ColumnIdentifierTableModel, it will
take the preferred size from that model directly.
table
- the table to calculate the column widthcol
- the column to calculate the widthsconsiderHeader
- 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.
public static int autoResizeColumn(JTable table, int col, boolean considerHeader, boolean visibleRowsOnly, int minimumWidth, int maximumWidth, boolean highPerformance, boolean respectColumnWidthTableModel)
ColumnIdentifierTableModel
will be considered first. If there is a ColumnIdentifierTableModel, it will
take the preferred size from that model directly.
table
- the table to calculate the column widthcol
- the column to calculate the widthsconsiderHeader
- 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.
public static int[] autoResizeAllColumns(JTable table)
JTable.setAutoResizeMode(int)
and set it to JTable.AUTO_RESIZE_OFF
. ColumnIdentifierTableModel
will be considered first. If there is a ColumnIdentifierTableModel, it will
take the preferred size from that model directly.
table
- the table to calculate the column widths
public static int[] autoResizeAllColumns(JTable table, boolean considerHeader)
JTable.setAutoResizeMode(int)
and set it to JTable.AUTO_RESIZE_OFF
. ColumnIdentifierTableModel
will be considered first. If there is a ColumnIdentifierTableModel, it will
take the preferred size from that model directly.
table
- the table to calculate the column widthsconsiderHeader
- 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.
public static int[] autoResizeAllColumns(JTable table, int[] minimumWidth, boolean considerHeader)
JTable.setAutoResizeMode(int)
and set it to JTable.AUTO_RESIZE_OFF
. ColumnIdentifierTableModel
will be considered first. If there is a ColumnIdentifierTableModel, it will
take the preferred size from that model directly.
table
- the table to calculate the column widthsminimumWidth
- 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.
public static int[] autoResizeAllColumns(JTable table, int[] minimumWidth, boolean considerHeader, boolean visibleRowsOnly)
JTable.setAutoResizeMode(int)
and set it to JTable.AUTO_RESIZE_OFF
. ColumnIdentifierTableModel
will be considered first. If there is a ColumnIdentifierTableModel, it will
take the preferred size from that model directly.
table
- the table to calculate the column widthsminimumWidth
- 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.
public static int[] autoResizeAllColumns(JTable table, int[] minimumWidth, int[] maximumWidth, boolean considerHeader, boolean visibleRowsOnly)
JTable.setAutoResizeMode(int)
and set it to JTable.AUTO_RESIZE_OFF
. ColumnIdentifierTableModel
will be considered first. If there is a ColumnIdentifierTableModel, it will
take the preferred size from that model directly.
table
- the table to calculate the column widthsminimumWidth
- 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.
public static int[] autoResizeAllColumns(JTable table, int[] minimumWidth, int[] maximumWidth, boolean considerHeader, boolean visibleRowsOnly, boolean highPerformance)
JTable.setAutoResizeMode(int)
and set it to JTable.AUTO_RESIZE_OFF
. ColumnIdentifierTableModel
will be considered first. If there is a ColumnIdentifierTableModel, it will
take the preferred size from that model directly.
table
- the table to calculate the column widthsminimumWidth
- 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.
public static int[] autoResizeAllColumns(JTable table, int[] minimumWidth, int[] maximumWidth, boolean considerHeader, boolean visibleRowsOnly, boolean highPerformance, boolean respectColumnWidthTableModel)
JTable.setAutoResizeMode(int)
and set it to JTable.AUTO_RESIZE_OFF
. ColumnIdentifierTableModel
will be considered first. If there is a ColumnIdentifierTableModel, it will
take the preferred size from that model directly.
table
- the table to calculate the column widthsminimumWidth
- 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.
public static boolean isTableColumnResizable(JTable table, TableColumn column)
table
- the tablecolumn
- the column index.
public static int autoResizeRow(JTable table, int row)
table
- the table to calculate the row heightrow
- the row to calculate the height
public static int autoResizeRow(JTable table, int row, int minimumHeight)
table
- the table to calculate the row heightrow
- the row to calculate the heightminimumHeight
- the minimum height of the row after resizing. -1 if there is no minimum height.
public static int[] autoResizeRows(JTable table, int fromRow, int toRow)
table
- the table to calculate the row heightsfromRow
- the beginning row to auto resizetoRow
- the end row to auto resize
public static int[] autoResizeRows(JTable table, int fromRow, int toRow, int[] minimumHeight)
table
- the table to calculate the row heightsfromRow
- the beginning row to auto resizetoRow
- the end row to auto resizeminimumHeight
- the minimum height of each row. It could be either null or the same length as the table row
count.
public static int[] autoResizeAllRows(JTable table)
table
- the table to calculate the row heights
public static int[] autoResizeAllRows(JTable table, int[] minimumHeight)
table
- the table to calculate the row heightsminimumHeight
- the minimum height of each row. It could be either null or the same length as the table row
count.
protected static int calculateRowHeight(JTable table, int row, int minimumHeight)
public static boolean stopCellEditingForAll(JTable table)
table
- the table
public static void ensureRowSelectionVisible(JTable table)
table
- the tablepublic static void ensureRowVisible(JTable table, int row)
table
- the tablerow
- the row indexpublic static int findColumnIndex(TableModel model, String columnName)
model
- the table model.columnName
- the column name
public static int[] findColumnIndexes(TableModel model, String[] columnNames)
model
- the table modelcolumnNames
- column names array
public static int getViewPositionForRow(JTable table, int row)
table
- the table.row
- the row index.
public static void setViewPositionForRow(JTable table, int row, int position)
table
- the table.row
- the row index.position
- the y position.public static void saveColumnOrders(JTable table, boolean isUngroup)
public static void clearColumnOrdersMemory(JTable table)
public static void saveDefaultColumnOrders(TableScrollPane pane, TableModel model)
public static void saveDefaultColumnOrders(GroupTable table)
public static void saveColumnOrders(TableScrollPane pane)
public static void clearColumnOrdersMemory(TableScrollPane pane)
public static TableColumn getResizingColumn(JTable table, Point p, int column)
table
- the resizing JTablep
- the point of the mouse eventcolumn
- the column
|
JIDE 3.5.15 | ||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |