public class TableHelper
extends java.lang.Object
Features provided by this TableHelper:
Constructor and Description |
---|
TableHelper() |
Modifier and Type | Method and Description |
---|---|
static int |
getCellWidth(javax.swing.JTable table, java.lang.Object value, int row, int col)
Return the preferred size of a table cell
|
static javax.swing.Action[] |
getColumnSelectorActions(javax.swing.JTable table)
Returns the additional ColumnSelector actions if it has been set before.
|
static java.lang.String |
getColumnSelectorToolTipText(javax.swing.JTable table)
Get the tooltip text for ColumnSelector button.
|
static int |
getDefaultRowHeight()
Returns the default row height for the table cell recommended by Oracle UI guidelines.
|
static int[] |
getHiddenColumns(javax.swing.JTable table)
Get columns that are hidden.
|
static java.lang.String |
getNoEntryInstructionText(javax.swing.JTable table)
Returns the instruction text of the table when there is no entry in the table.
|
static int |
getPreferredVisibleRowCount(javax.swing.JTable table)
Returns the value of the
visibleRowCount property. |
static javax.swing.Action |
getSelectColumnsAction(javax.swing.JTable table)
Returns the additional select columns action if it has been set before.
|
static javax.swing.Icon |
getSortIconDown()
Returns the column sort icon when the sort order is descending to be displayed on the table header.
|
static javax.swing.Icon |
getSortIconUp()
Returns the column sort icon when the sort order is ascending to be displayed on the table header.
|
static java.lang.String |
getTruncatedCellValue(javax.swing.JTable table, int row, int col)
Figure out if the renderer has been truncated by the column width and if so return the complete value of the cell.
|
static void |
installGenericTableRenderer(javax.swing.JTable table)
Set GenericTableCellRenderer for objects, numbers, doubles, dates, booleans, and icons column class type of this table.
|
static void |
installTableTransferHandler(javax.swing.JTable table, boolean supportsPaste)
Installs TableTransferHandler that supports copy and paste
|
static boolean |
isColumnHeaderSelectionEnabled(javax.swing.JTable table)
Returns whether column header selection is supported for the table.
|
static boolean |
isColumnSelectorAvailable(javax.swing.JTable table)
Get whether the dropdown button is displayed at the end of the column header for hiding and showing columns is available on this instance of table.
|
static boolean |
isResizeColumnOnDoubleClick(javax.swing.JTable table)
Get whether the user can resize columns in this table by double clicking the resize divider between two columns.
|
static boolean |
isRolloverHighlightingEnabled(javax.swing.JTable table)
Returns whether rollover highlighting is enabled/disabled on the table.
|
static boolean |
isSelectAllEnabled(javax.swing.JTable table)
Returns whether selectAll feature is enabled for the table.
|
static void |
setColumnHeaderSelectionEnabled(javax.swing.JTable table, boolean select)
Add column header selection support for the table.
|
static void |
setColumnSelectorActions(javax.swing.JTable table, javax.swing.Action... actions)
This method adds the specified actions to the end of ColumnSelector dropdow menu.
|
static void |
setColumnSelectorAvailable(javax.swing.JTable table, boolean isAvailable)
Set whether this table will display a dropdown button at the end of the column header to hide/show columns.
|
static void |
setColumnSelectorToolTipText(javax.swing.JTable table, java.lang.String text)
Sets the tooltip text for ColumnSelector button.
|
static void |
setHiddenColumns(javax.swing.JTable table, int... hiddenColumns)
Set columns that are hidden.
|
static void |
setHiddenColumnsVisible(javax.swing.JTable table, int... columns)
Set columns that were previously hidden visible again.
|
static void |
setNoEntryInstructionText(javax.swing.JTable table, java.lang.String text)
Sets the instruction text on the firt row of the table when there is no entry in the table.
|
static void |
setPreferredVisibleRowCount(javax.swing.JTable table, int visibleRowCount)
Sets the
visibleRowCount property. |
static void |
setResizeColumnOnDoubleClick(javax.swing.JTable table, boolean isOn)
Set whether the user can resize columns in this table by double clicking the resize divider between two columns.
|
static void |
setRolloverHighlightingEnabled(javax.swing.JTable table, boolean enable)
Set rollover highlighting enabled/disabled on the table.
|
static void |
setSelectAllEnabled(javax.swing.JTable table, javax.swing.JScrollPane pane, boolean enable)
Enables whether the user can click on upper left corner to select all cells in the table by clicking on it.
|
static void |
setSelectColumnsAction(javax.swing.JTable table, javax.swing.Action selectColumn)
This method adds the specified SelectColumns action to the end of ColumnSelector dropdow menu.
|
static void |
setVisibleRows(javax.swing.JTable table, javax.swing.JScrollPane sp, int rows)
Set the preferred size of the scrollpane to the desired number of visible table rows.
|
static int |
sizeColumnToContents(javax.swing.JTable table, int col, boolean sortCol, int sampleSize, java.lang.Object[] prototypeValues)
Size one column of a table to be just large enough to fully display its current contents.
|
static void |
sizeColumnToContents(javax.swing.JTable table, int col, int sampleSize)
Size one column of a table to be just large enough to fully display its current contents.
|
static void |
sizeColumnToMaximumWidth(javax.swing.JTable table, int x)
Size the column in the table at location x to the maximum width of all cells in that column.
|
static void |
sizeTableToContents(javax.swing.JTable table) |
static void |
sizeTableToContents(javax.swing.JTable table, java.lang.Object[] prototypeValues)
Utility method that will set the preferred size of all columns in this table so that they are just big enough to display their contents.
|
static void |
stopCellEditing(javax.swing.JTable table)
Utility method to stop cell editing in the table.
|
public static void setColumnSelectorAvailable(javax.swing.JTable table, boolean isAvailable)
isAvailable
- if true, a dropdown button will be provided at the end of the column header of this table with checkbox menu items for each column. The user can use these to hide and show columns.public static boolean isColumnSelectorAvailable(javax.swing.JTable table)
public static void setSelectColumnsAction(javax.swing.JTable table, javax.swing.Action selectColumn)
public static javax.swing.Action getSelectColumnsAction(javax.swing.JTable table)
public static void setColumnSelectorActions(javax.swing.JTable table, javax.swing.Action... actions)
public static javax.swing.Action[] getColumnSelectorActions(javax.swing.JTable table)
public static void setHiddenColumns(javax.swing.JTable table, int... hiddenColumns)
hiddenColumns
- columns which are currently hiddenpublic static int[] getHiddenColumns(javax.swing.JTable table)
public static void setHiddenColumnsVisible(javax.swing.JTable table, int... columns)
columns
- An array of hidden columns to be made visiblepublic static void setColumnSelectorToolTipText(javax.swing.JTable table, java.lang.String text)
public static java.lang.String getColumnSelectorToolTipText(javax.swing.JTable table)
public static void setNoEntryInstructionText(javax.swing.JTable table, java.lang.String text)
public static java.lang.String getNoEntryInstructionText(javax.swing.JTable table)
public static void installGenericTableRenderer(javax.swing.JTable table)
public static void setResizeColumnOnDoubleClick(javax.swing.JTable table, boolean isOn)
table.setAutoResizeMode( JTable.AUTO_RESIZE_OFF );
isOn
- if true, the user can resize columnspublic static boolean isResizeColumnOnDoubleClick(javax.swing.JTable table)
public static void sizeTableToContents(javax.swing.JTable table)
sizeTableToContents(JTable, Object[])
public static void sizeTableToContents(javax.swing.JTable table, java.lang.Object[] prototypeValues)
table.setAutoResizeMode( JTable.AUTO_RESIZE_OFF );
public static void sizeColumnToContents(javax.swing.JTable table, int col, int sampleSize)
public static int getCellWidth(javax.swing.JTable table, java.lang.Object value, int row, int col)
public static void sizeColumnToMaximumWidth(javax.swing.JTable table, int x)
public static int sizeColumnToContents(javax.swing.JTable table, int col, boolean sortCol, int sampleSize, java.lang.Object[] prototypeValues)
public static void setVisibleRows(javax.swing.JTable table, javax.swing.JScrollPane sp, int rows)
public static void setPreferredVisibleRowCount(javax.swing.JTable table, int visibleRowCount)
visibleRowCount
property. This sets the preferred number of rows to display without requiring scrolling. Setting this property affects the return value of the JTable.getPreferredScrollableViewportSize method, which is used to calculate the preferred size of an enclosing viewport. See that method's documentation for more details.
The default value of this property is -1
, indicating null PreferredScrollableViewportSize.
Calling this method with a negative value will set the PreferredScrollableViewportSize to null.
visibleRowCount
- an integer specifying the preferred number of rows to display without requiring scrollinggetPreferredVisibleRowCount(javax.swing.JTable)
public static int getPreferredVisibleRowCount(javax.swing.JTable table)
visibleRowCount
property. See the documentation for setPreferredVisibleRowCount(javax.swing.JTable, int)
for details on how to interpret this value.visibleRowCount
property.setPreferredVisibleRowCount(javax.swing.JTable, int)
public static int getDefaultRowHeight()
public static void setColumnHeaderSelectionEnabled(javax.swing.JTable table, boolean select)
public static boolean isColumnHeaderSelectionEnabled(javax.swing.JTable table)
public static void setSelectAllEnabled(javax.swing.JTable table, javax.swing.JScrollPane pane, boolean enable)
public static boolean isSelectAllEnabled(javax.swing.JTable table)
public static void setRolloverHighlightingEnabled(javax.swing.JTable table, boolean enable)
public static boolean isRolloverHighlightingEnabled(javax.swing.JTable table)
public static void installTableTransferHandler(javax.swing.JTable table, boolean supportsPaste)
public static java.lang.String getTruncatedCellValue(javax.swing.JTable table, int row, int col)
public static void stopCellEditing(javax.swing.JTable table)
public static javax.swing.Icon getSortIconUp()
public static javax.swing.Icon getSortIconDown()