JTable (Java Platform SE 7 )

Methods

 

Modifier and Type
Method and Description

void
addColumn(TableColumn aColumn)

Appends aColumn to the end of the array of columns held by
this JTable‘s column model.

void
addColumnSelectionInterval(int index0,
int index1)

Adds the columns from index0 to index1,
inclusive, to the current selection.

void
addNotify()

Calls the configureEnclosingScrollPane method.

void
addRowSelectionInterval(int index0,
int index1)

Adds the rows from index0 to index1, inclusive, to
the current selection.

void
changeSelection(int rowIndex,
int columnIndex,
boolean toggle,
boolean extend)

Updates the selection models of the table, depending on the state of the
two flags: toggle and extend.

void
clearSelection()

Deselects all selected columns and rows.

void
columnAdded(TableColumnModelEvent e)

Invoked when a column is added to the table column model.

int
columnAtPoint(Point point)

Returns the index of the column that point lies in,
or -1 if the result is not in the range
[0, getColumnCount()-1].

void
columnMarginChanged(ChangeEvent e)

Invoked when a column is moved due to a margin change.

void
columnMoved(TableColumnModelEvent e)

Invoked when a column is repositioned.

void
columnRemoved(TableColumnModelEvent e)

Invoked when a column is removed from the table column model.

void
columnSelectionChanged(ListSelectionEvent e)

Invoked when the selection model of the TableColumnModel
is changed.

protected void
configureEnclosingScrollPane()

If this JTable is the viewportView of an enclosing JScrollPane
(the usual situation), configure this ScrollPane by, amongst other things,
installing the table’s tableHeader as the columnHeaderView of the scroll pane.

int
convertColumnIndexToModel(int viewColumnIndex)

Maps the index of the column in the view at
viewColumnIndex to the index of the column
in the table model.

int
convertColumnIndexToView(int modelColumnIndex)

Maps the index of the column in the table model at
modelColumnIndex to the index of the column
in the view.

int
convertRowIndexToModel(int viewRowIndex)

Maps the index of the row in terms of the view to the
underlying TableModel.

int
convertRowIndexToView(int modelRowIndex)

Maps the index of the row in terms of the
TableModel to the view.

protected TableColumnModel
createDefaultColumnModel()

Returns the default column model object, which is
a DefaultTableColumnModel.

void
createDefaultColumnsFromModel()

Creates default columns for the table from
the data model using the getColumnCount method
defined in the TableModel interface.

protected TableModel
createDefaultDataModel()

Returns the default table model object, which is
a DefaultTableModel.

protected void
createDefaultEditors()

Creates default cell editors for objects, numbers, and boolean values.

protected void
createDefaultRenderers()

Creates default cell renderers for objects, numbers, doubles, dates,
booleans, and icons.

protected ListSelectionModel
createDefaultSelectionModel()

Returns the default selection model object, which is
a DefaultListSelectionModel.

protected JTableHeader
createDefaultTableHeader()

Returns the default table header object, which is
a JTableHeader.

static JScrollPane
createScrollPaneForTable(JTable aTable)
Deprecated. 

As of Swing version 1.0.2,
replaced by new JScrollPane(aTable).

void
doLayout()

Causes this table to lay out its rows and columns.

boolean
editCellAt(int row,
int column)

Programmatically starts editing the cell at row and
column, if those indices are in the valid range, and
the cell at those indices is editable.

boolean
editCellAt(int row,
int column,
EventObject e)

Programmatically starts editing the cell at row and
column, if those indices are in the valid range, and
the cell at those indices is editable.

void
editingCanceled(ChangeEvent e)

Invoked when editing is canceled.

void
editingStopped(ChangeEvent e)

Invoked when editing is finished.

AccessibleContext
getAccessibleContext()

Gets the AccessibleContext associated with this JTable.

boolean
getAutoCreateColumnsFromModel()

Determines whether the table will create default columns from the model.

boolean
getAutoCreateRowSorter()

Returns true if whenever the model changes, a new
RowSorter should be created and installed
as the table’s sorter; otherwise, returns false.

int
getAutoResizeMode()

Returns the auto resize mode of the table.

TableCellEditor
getCellEditor()

Returns the active cell editor, which is null if the table
is not currently editing.

TableCellEditor
getCellEditor(int row,
int column)

Returns an appropriate editor for the cell specified by
row and column.

Rectangle
getCellRect(int row,
int column,
boolean includeSpacing)

Returns a rectangle for the cell that lies at the intersection of
row and column.

TableCellRenderer
getCellRenderer(int row,
int column)

Returns an appropriate renderer for the cell specified by this row and
column.

boolean
getCellSelectionEnabled()

Returns true if both row and column selection models are enabled.

TableColumn
getColumn(Object identifier)

Returns the TableColumn object for the column in the table
whose identifier is equal to identifier, when compared using
equals.

Class<?>
getColumnClass(int column)

Returns the type of the column appearing in the view at
column position column.

int
getColumnCount()

Returns the number of columns in the column model.

TableColumnModel
getColumnModel()

Returns the TableColumnModel that contains all column information
of this table.

String
getColumnName(int column)

Returns the name of the column appearing in the view at
column position column.

boolean
getColumnSelectionAllowed()

Returns true if columns can be selected.

TableCellEditor
getDefaultEditor(Class<?> columnClass)

Returns the editor to be used when no editor has been set in
a TableColumn.

TableCellRenderer
getDefaultRenderer(Class<?> columnClass)

Returns the cell renderer to be used when no renderer has been set in
a TableColumn.

boolean
getDragEnabled()

Returns whether or not automatic drag handling is enabled.

JTable.DropLocation
getDropLocation()

Returns the location that this component should visually indicate
as the drop location during a DnD operation over the component,
or null if no location is to currently be shown.

DropMode
getDropMode()

Returns the drop mode for this component.

int
getEditingColumn()

Returns the index of the column that contains the cell currently
being edited.

int
getEditingRow()

Returns the index of the row that contains the cell currently
being edited.

Component
getEditorComponent()

Returns the component that is handling the editing session.

boolean
getFillsViewportHeight()

Returns whether or not this table is always made large enough
to fill the height of an enclosing viewport.

Color
getGridColor()

Returns the color used to draw grid lines.

Dimension
getIntercellSpacing()

Returns the horizontal and vertical space between cells.

TableModel
getModel()

Returns the TableModel that provides the data displayed by this
JTable.

Dimension
getPreferredScrollableViewportSize()

Returns the preferred size of the viewport for this table.

Printable
getPrintable(JTable.PrintMode printMode,
MessageFormat headerFormat,
MessageFormat footerFormat)

Return a Printable for use in printing this JTable.

int
getRowCount()

Returns the number of rows that can be shown in the
JTable, given unlimited space.

int
getRowHeight()

Returns the height of a table row, in pixels.

int
getRowHeight(int row)

Returns the height, in pixels, of the cells in row.

int
getRowMargin()

Gets the amount of empty space, in pixels, between cells.

boolean
getRowSelectionAllowed()

Returns true if rows can be selected.

RowSorter<? extends TableModel>
getRowSorter()

Returns the object responsible for sorting.

int
getScrollableBlockIncrement(Rectangle visibleRect,
int orientation,
int direction)

Returns visibleRect.height or
visibleRect.width,
depending on this table’s orientation.

boolean
getScrollableTracksViewportHeight()

Returns false to indicate that the height of the viewport does
not determine the height of the table, unless
getFillsViewportHeight is true and the preferred height
of the table is smaller than the viewport’s height.

boolean
getScrollableTracksViewportWidth()

Returns false if autoResizeMode is set to
AUTO_RESIZE_OFF, which indicates that the
width of the viewport does not determine the width
of the table.

int
getScrollableUnitIncrement(Rectangle visibleRect,
int orientation,
int direction)

Returns the scroll increment (in pixels) that completely exposes one new
row or column (depending on the orientation).

int
getSelectedColumn()

Returns the index of the first selected column,
-1 if no column is selected.

int
getSelectedColumnCount()

Returns the number of selected columns.

int[]
getSelectedColumns()

Returns the indices of all selected columns.

int
getSelectedRow()

Returns the index of the first selected row, -1 if no row is selected.

int
getSelectedRowCount()

Returns the number of selected rows.

int[]
getSelectedRows()

Returns the indices of all selected rows.

Color
getSelectionBackground()

Returns the background color for selected cells.

Color
getSelectionForeground()

Returns the foreground color for selected cells.

ListSelectionModel
getSelectionModel()

Returns the ListSelectionModel that is used to maintain row
selection state.

boolean
getShowHorizontalLines()

Returns true if the table draws horizontal lines between cells, false if it
doesn’t.

boolean
getShowVerticalLines()

Returns true if the table draws vertical lines between cells, false if it
doesn’t.

boolean
getSurrendersFocusOnKeystroke()

Returns true if the editor should get the focus
when keystrokes cause the editor to be activated

JTableHeader
getTableHeader()

Returns the tableHeader used by this JTable.

String
getToolTipText(MouseEvent event)

Overrides JComponent‘s getToolTipText
method in order to allow the renderer’s tips to be used
if it has text set.

TableUI
getUI()

Returns the L&F object that renders this component.

String
getUIClassID()

Returns the suffix used to construct the name of the L&F class used to
render this component.

boolean
getUpdateSelectionOnSort()

Returns true if the selection should be updated after sorting.

Object
getValueAt(int row,
int column)

Returns the cell value at row and column.

protected void
initializeLocalVars()

Initializes table properties to their default values.

boolean
isCellEditable(int row,
int column)

Returns true if the cell at row and column
is editable.

boolean
isCellSelected(int row,
int column)

Returns true if the specified indices are in the valid range of rows
and columns and the cell at the specified position is selected.

boolean
isColumnSelected(int column)

Returns true if the specified index is in the valid range of columns,
and the column at that index is selected.

boolean
isEditing()

Returns true if a cell is being edited.

boolean
isRowSelected(int row)

Returns true if the specified index is in the valid range of rows,
and the row at that index is selected.

void
moveColumn(int column,
int targetColumn)

Moves the column column to the position currently
occupied by the column targetColumn in the view.

protected String
paramString()

Returns a string representation of this table.

Component
prepareEditor(TableCellEditor editor,
int row,
int column)

Prepares the editor by querying the data model for the value and
selection state of the cell at row, column.

Component
prepareRenderer(TableCellRenderer renderer,
int row,
int column)

Prepares the renderer by querying the data model for the
value and selection state
of the cell at row, column.

boolean
print()

A convenience method that displays a printing dialog, and then prints
this JTable in mode PrintMode.FIT_WIDTH,
with no header or footer text.

boolean
print(JTable.PrintMode printMode)

A convenience method that displays a printing dialog, and then prints
this JTable in the given printing mode,
with no header or footer text.

boolean
print(JTable.PrintMode printMode,
MessageFormat headerFormat,
MessageFormat footerFormat)

A convenience method that displays a printing dialog, and then prints
this JTable in the given printing mode,
with the specified header and footer text.

boolean
print(JTable.PrintMode printMode,
MessageFormat headerFormat,
MessageFormat footerFormat,
boolean showPrintDialog,
PrintRequestAttributeSet attr,
boolean interactive)

Prints this table, as specified by the fully featured print method, with the default printer specified as the print service.

boolean
print(JTable.PrintMode printMode,
MessageFormat headerFormat,
MessageFormat footerFormat,
boolean showPrintDialog,
PrintRequestAttributeSet attr,
boolean interactive,
PrintService service)

Prints this JTable.

protected boolean
processKeyBinding(KeyStroke ks,
KeyEvent e,
int condition,
boolean pressed)

Invoked to process the key bindings for ks as the result
of the KeyEvent e.

void
removeColumn(TableColumn aColumn)

Removes aColumn from this JTable‘s
array of columns.

void
removeColumnSelectionInterval(int index0,
int index1)

Deselects the columns from index0 to index1, inclusive.

void
removeEditor()

Discards the editor object and frees the real estate it used for
cell rendering.

void
removeNotify()

Calls the unconfigureEnclosingScrollPane method.

void
removeRowSelectionInterval(int index0,
int index1)

Deselects the rows from index0 to index1, inclusive.

protected void
resizeAndRepaint()

Equivalent to revalidate followed by repaint.

int
rowAtPoint(Point point)

Returns the index of the row that point lies in,
or -1 if the result is not in the range
[0, getRowCount()-1].

void
selectAll()

Selects all rows, columns, and cells in the table.

void
setAutoCreateColumnsFromModel(boolean autoCreateColumnsFromModel)

Sets this table’s autoCreateColumnsFromModel flag.

void
setAutoCreateRowSorter(boolean autoCreateRowSorter)

Specifies whether a RowSorter should be created for the
table whenever its model changes.

void
setAutoResizeMode(int mode)

Sets the table’s auto resize mode when the table is resized.

void
setCellEditor(TableCellEditor anEditor)

Sets the active cell editor.

void
setCellSelectionEnabled(boolean cellSelectionEnabled)

Sets whether this table allows both a column selection and a
row selection to exist simultaneously.

void
setColumnModel(TableColumnModel columnModel)

Sets the column model for this table to newModel and registers
for listener notifications from the new column model.

void
setColumnSelectionAllowed(boolean columnSelectionAllowed)

Sets whether the columns in this model can be selected.

void
setColumnSelectionInterval(int index0,
int index1)

Selects the columns from index0 to index1,
inclusive.

void
setDefaultEditor(Class<?> columnClass,
TableCellEditor editor)

Sets a default cell editor to be used if no editor has been set in
a TableColumn.

void
setDefaultRenderer(Class<?> columnClass,
TableCellRenderer renderer)

Sets a default cell renderer to be used if no renderer has been set in
a TableColumn.

void
setDragEnabled(boolean b)

Turns on or off automatic drag handling.

void
setDropMode(DropMode dropMode)

Sets the drop mode for this component.

void
setEditingColumn(int aColumn)

Sets the editingColumn variable.

void
setEditingRow(int aRow)

Sets the editingRow variable.

void
setFillsViewportHeight(boolean fillsViewportHeight)

Sets whether or not this table is always made large enough
to fill the height of an enclosing viewport.

void
setGridColor(Color gridColor)

Sets the color used to draw grid lines to gridColor and redisplays.

void
setIntercellSpacing(Dimension intercellSpacing)

Sets the rowMargin and the columnMargin
the height and width of the space between cells — to
intercellSpacing.

void
setModel(TableModel dataModel)

Sets the data model for this table to newModel and registers
with it for listener notifications from the new data model.

void
setPreferredScrollableViewportSize(Dimension size)

Sets the preferred size of the viewport for this table.

void
setRowHeight(int rowHeight)

Sets the height, in pixels, of all cells to rowHeight,
revalidates, and repaints.

void
setRowHeight(int row,
int rowHeight)

Sets the height for row to rowHeight,
revalidates, and repaints.

void
setRowMargin(int rowMargin)

Sets the amount of empty space between cells in adjacent rows.

void
setRowSelectionAllowed(boolean rowSelectionAllowed)

Sets whether the rows in this model can be selected.

void
setRowSelectionInterval(int index0,
int index1)

Selects the rows from index0 to index1,
inclusive.

void
setRowSorter(RowSorter<? extends TableModel> sorter)

Sets the RowSorter.

void
setSelectionBackground(Color selectionBackground)

Sets the background color for selected cells.

void
setSelectionForeground(Color selectionForeground)

Sets the foreground color for selected cells.

void
setSelectionMode(int selectionMode)

Sets the table’s selection mode to allow only single selections, a single
contiguous interval, or multiple intervals.

void
setSelectionModel(ListSelectionModel newModel)

Sets the row selection model for this table to newModel
and registers for listener notifications from the new selection model.

void
setShowGrid(boolean showGrid)

Sets whether the table draws grid lines around cells.

void
setShowHorizontalLines(boolean showHorizontalLines)

Sets whether the table draws horizontal lines between cells.

void
setShowVerticalLines(boolean showVerticalLines)

Sets whether the table draws vertical lines between cells.

void
setSurrendersFocusOnKeystroke(boolean surrendersFocusOnKeystroke)

Sets whether editors in this JTable get the keyboard focus
when an editor is activated as a result of the JTable
forwarding keyboard events for a cell.

void
setTableHeader(JTableHeader tableHeader)

Sets the tableHeader working with this JTable to newHeader.

void
setUI(TableUI ui)

Sets the L&F object that renders this component and repaints.

void
setUpdateSelectionOnSort(boolean update)

Specifies whether the selection should be updated after sorting.

void
setValueAt(Object aValue,
int row,
int column)

Sets the value for the cell in the table model at row
and column.

void
sizeColumnsToFit(boolean lastColumnOnly)
Deprecated. 

As of Swing version 1.0.3,
replaced by doLayout().

void
sizeColumnsToFit(int resizingColumn)

Obsolete as of Java 2 platform v1.4.

void
sorterChanged(RowSorterEvent e)

RowSorterListener notification that the
RowSorter has changed in some way.

void
tableChanged(TableModelEvent e)

Invoked when this table’s TableModel generates
a TableModelEvent.

protected void
unconfigureEnclosingScrollPane()

Reverses the effect of configureEnclosingScrollPane
by replacing the columnHeaderView of the enclosing
scroll pane with null.

void
updateUI()

Notification from the UIManager that the L&F has changed.

void
valueChanged(ListSelectionEvent e)

Invoked when the row selection changes — repaints to show the new
selection.