|
Holger's Java API |
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectcom.antelmann.util.table.TableUtils
public class TableUtils
some utilities for tables
| Nested Class Summary | |
|---|---|
static class |
TableUtils.BooleanRenderer
thanks for JTable for not making this available externally :( |
| Method Summary | |
|---|---|
static TableModelListener |
addRowHeightAdjuster(JTable table)
adds a TableModelListener to the table's model, which adjusts row heights when data changes |
static void |
adjustColumnWidths(int maxRowsToConsider,
JTable table,
int... columnToAdjust)
adjust the widths of the columns so that the header and the given number of rows fit into the cell. |
static void |
adjustColumnWidths(JTable table)
adjust the widths of the columns so that all content fits into the cell properly |
static void |
adjustRowHeights(JTable table)
adjusts the height of every row for the entire table. |
static void |
adjustRowHeights(JTable table,
int beginRow,
int endRow)
adjusts the height of the given rows based on the maximum preferred height of each renderer for any given row. |
static void |
copy(TableModel source,
Rectangle sourceRegion,
TableModel target,
Point targetBegin)
copies the sourceRegion from the source into the target beginning at the given point |
static void |
copy(TableModel source,
TableModel target)
copies the entire source table into the target table |
static CounterMap<Object> |
count(TableModel model,
int... columns)
|
static CounterMap<Object> |
count(TableModel model,
String... columns)
|
static DefaultTableModel |
createSampleModel(int rowCount)
provides a quick sample model for testing purposes |
static JTable |
createStretchedTable()
creates a table that 'stretches' over the viewport of a JScrollPane, even if the table itself is smaller than that. |
static JTable |
createStretchedTable(TableModel model)
creates a table that 'stretches' over the viewport of a JScrollPane, even if the table itself is smaller than that. |
static void |
delegateRenderingToModel(JTable table)
|
static void |
delegateRenderingToModel(JTable table,
TableCellRenderer defaultRenderer)
sets all columns of the given table to be rendered by a TableModelRenderer |
static void |
editColumnAsPercent(JTable table,
int column)
sets appropriate editor and renderer for the given column, so that it can be displayed/edited as a percent value in a consistent way |
static void |
editColumnAsPercent(JTable table,
int column,
Locale l)
sets appropriate editor and renderer for the given column, so that it can be displayed/edited as a percent value in a consistent way |
static void |
enableEditAction(JTable table,
ActionListener al,
String actionName)
sets the given ActionListener to be activated upon either double-mouse-click or pressing enter when a table row is selected |
static void |
enableToolTips(JTable table)
wraps any given TableCellRenderer with a ToolTipRenderer in all columns |
static void |
enableToolTipsForHeader(JTable table)
sets the column name as the tool tip for all column headers |
static JPanel |
fitToPanel(JTable table,
boolean showHeader)
creates a special JPanel that is filled with the given table while the row height adjusts automatically to the size of the JPanel, so that all rows have equal space in the component. |
static JTable |
fixColumns(JScrollPane scrollPane,
int fixedColumns)
fixes the first given number of columns in the given JScrollPane so that these first columns won't scroll horizontally anymore. |
static TableCellEditor |
getColorEditor()
edits Color objects |
static TableCellRenderer |
getColorRenderer()
renders Color objects |
static int |
getColumn(TableModel model,
String columnName)
if the column name is not found, -1 is returned |
static String[] |
getColumnNames(TableModel model)
|
static HashSet<Object> |
getColumnValues(TableModel model,
int column)
|
static Component |
getComponentFor(AbstractTableModel model)
useful to show a dialog from within a TableModel (while setting a value, for instance), where no Component is readily available. |
static CurrencyCellRenderer |
getCurrencyRenderer(boolean useToolTipText)
|
static FormattedCellEditor |
getDateEditor()
edits Date objects |
static TableCellEditor |
getFontEditor()
edits Font objects |
static TableCellRenderer |
getFontRenderer()
renders Font objects |
static int |
getMaxPreferredRowHeight(JTable table)
|
static int |
getMaxPreferredRowHeight(JTable table,
int beginRow,
int endRow)
|
static TableCellRenderer |
getMultiRenderer()
|
static FilteredTableModel |
getSelectedRowsAsModel(JTable table)
|
static TimeCellRenderer |
getTimeRenderer(boolean useToolTipText)
renders Date and Long objects |
static DefaultTableCellRenderer |
getToolTipRenderer()
provides a tool tip based on the toString() method of the cell object. |
static DefaultTableCellRenderer |
getToolTipRenderer(TableCellRenderer renderer)
provides a tool tip based on the toString() method of the cell object; otherwise, the given formatter is used |
static void |
makeColumnWithAdjustable(JTable table)
adds a mouse listener to the header that will resize the column width on double-click on the header |
static JTable |
makePropertiesTable(Map<?,?> properties)
calls makePropertiesTable(properties, "key", "value") |
static JTable |
makePropertiesTable(Map<?,?> properties,
String keyHeader,
String valueHeader)
|
static SortableTableModel |
makeSortable(JTable table,
Comparator<?>... comp)
|
static SortableTableModel |
makeSortable(JTable table,
List<Comparator<?>> comp)
wraps the TableModel with a SortableTableModel, replaces the model of the table with the same and registers a MouseListener on the table header to support sorting. |
static DefaultTableModel |
makeTableModel(Map<?,?> map)
|
static DefaultTableModel |
makeTableModel(Map<?,?> map,
String keyHeader,
String valueHeader)
creates a read-only model |
static TableModelWrapper |
readOnly(TableModel model)
|
static boolean |
removeSortableListener(JTable table)
|
static HashMap<String,Object> |
rowToMap(TableModel model,
int row)
|
static void |
scrollToRow(JTable table,
int row)
convenience method |
static TableCellEditor |
selectAllTableCellEditor(TableCellEditor editor)
wraps the given editor into one that will select all text upon editing, provided that the given editor will use a JTextComponent as a Component. |
static void |
setTerminateEditOnFocusLost(JTable table,
boolean flag)
setting this to true fixes an annoying problem of editor values not being committed when the table looses focus. |
static void |
setToolTipForHeader(JTable table,
int columnIndex,
String tooltip)
for more specific header rendering options, see LabelRenderer |
static void |
setToolTipForHeader(JTable table,
String columnName,
String tooltip)
for more specific header rendering options, see LabelRenderer |
static boolean |
stopCellEditing(JTable table)
useful to ensure that all cells stop editing before another action relies on the entered values |
static String |
toString(TableModel model,
boolean includeHeader)
|
static String |
toString(TableModel model,
boolean includeHeader,
String columnDelimiter,
String rowDelimiter)
|
static void |
wrapEditorToSelectAll(JTable table,
int column)
wraps the TableCellEditor of the given column into one that will select all on editing |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Method Detail |
|---|
public static TableCellRenderer getMultiRenderer()
public static TableCellRenderer getColorRenderer()
public static TableCellEditor getColorEditor()
public static FormattedCellEditor getDateEditor()
public static TableCellRenderer getFontRenderer()
public static TableCellEditor getFontEditor()
public static TimeCellRenderer getTimeRenderer(boolean useToolTipText)
public static CurrencyCellRenderer getCurrencyRenderer(boolean useToolTipText)
public static DefaultTableCellRenderer getToolTipRenderer()
Strings.encodeXML(String)public static DefaultTableCellRenderer getToolTipRenderer(TableCellRenderer renderer)
public static void delegateRenderingToModel(JTable table)
delegateRenderingToModel(JTable, TableCellRenderer)
public static void delegateRenderingToModel(JTable table,
TableCellRenderer defaultRenderer)
TableModelRenderer
TableModelRenderer
public static void setTerminateEditOnFocusLost(JTable table,
boolean flag)
stopCellEditing(JTable)public static boolean stopCellEditing(JTable table)
setTerminateEditOnFocusLost(JTable, boolean)public static void enableToolTips(JTable table)
public static void enableToolTipsForHeader(JTable table)
setToolTipForHeader(JTable, int, String)
public static void setToolTipForHeader(JTable table,
String columnName,
String tooltip)
LabelRenderer
public static void setToolTipForHeader(JTable table,
int columnIndex,
String tooltip)
LabelRenderer
public static void editColumnAsPercent(JTable table,
int column)
public static void editColumnAsPercent(JTable table,
int column,
Locale l)
public static void wrapEditorToSelectAll(JTable table,
int column)
selectAllTableCellEditor(TableCellEditor)public static TableCellEditor selectAllTableCellEditor(TableCellEditor editor)
public static void adjustColumnWidths(JTable table)
public static void adjustColumnWidths(int maxRowsToConsider,
JTable table,
int... columnToAdjust)
public static Component getComponentFor(AbstractTableModel model)
public static TableModelWrapper readOnly(TableModel model)
public static HashMap<String,Object> rowToMap(TableModel model,
int row)
public static JTable makePropertiesTable(Map<?,?> properties)
makePropertiesTable(properties, "key", "value")
public static JTable makePropertiesTable(Map<?,?> properties,
String keyHeader,
String valueHeader)
public static DefaultTableModel makeTableModel(Map<?,?> map)
public static DefaultTableModel makeTableModel(Map<?,?> map,
String keyHeader,
String valueHeader)
public static boolean removeSortableListener(JTable table)
makeSortable(JTable, List)
public static SortableTableModel makeSortable(JTable table,
Comparator<?>... comp)
public static SortableTableModel makeSortable(JTable table,
List<Comparator<?>> comp)
SortableTableModel,
removeSortableListener(JTable)public static void makeColumnWithAdjustable(JTable table)
public static TableModelListener addRowHeightAdjuster(JTable table)
adjustRowHeights(javax.swing.JTable, int, int)
public static JPanel fitToPanel(JTable table,
boolean showHeader)
public static int getMaxPreferredRowHeight(JTable table)
public static int getMaxPreferredRowHeight(JTable table,
int beginRow,
int endRow)
public static void adjustRowHeights(JTable table)
public static void adjustRowHeights(JTable table,
int beginRow,
int endRow)
public static void scrollToRow(JTable table,
int row)
public static void enableEditAction(JTable table,
ActionListener al,
String actionName)
public static JTable createStretchedTable()
public static JTable createStretchedTable(TableModel model)
public static int getColumn(TableModel model,
String columnName)
public static void copy(TableModel source,
TableModel target)
public static void copy(TableModel source,
Rectangle sourceRegion,
TableModel target,
Point targetBegin)
public static CounterMap<Object> count(TableModel model,
String... columns)
public static CounterMap<Object> count(TableModel model,
int... columns)
public static String[] getColumnNames(TableModel model)
public static JTable fixColumns(JScrollPane scrollPane,
int fixedColumns)
throws IllegalArgumentException
scrollPane - the scroll pane that must have JTable as its viewportfixedColumns - the number of columns that are to be fixed on the left side
IllegalArgumentExceptionpublic static DefaultTableModel createSampleModel(int rowCount)
public static String toString(TableModel model,
boolean includeHeader)
public static String toString(TableModel model,
boolean includeHeader,
String columnDelimiter,
String rowDelimiter)
public static FilteredTableModel getSelectedRowsAsModel(JTable table)
public static HashSet<Object> getColumnValues(TableModel model,
int column)
|
|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||