javax.swing

Class JTable

public class JTable extends JComponent implements TableModelListener, Scrollable, TableColumnModelListener, ListSelectionListener, CellEditorListener, Accessible

The table component, displaying information, organized in rows and columns. The table can be placed in the scroll bar and have the optional header that is always visible. Cell values may be editable after double clicking on the cell. Cell columns may have various data types, that are displayed and edited by the different renderers and editors. It is possible to set different column width. The columns are also resizeable by dragging the column boundary in the header.
Nested Class Summary
protected classJTable.AccessibleJTable
Provides accessibility support for JTable.
Field Summary
static intAUTO_RESIZE_ALL_COLUMNS
When resizing column i in a table of n columns, automatically change all columns in the range [0, n) (with the exception of column i) uniformly, to provide or absorb excess space requirements.
static intAUTO_RESIZE_LAST_COLUMN
When resizing column i in a table of n columns, automatically change column n-1 (the last column in the table) to provide or absorb excess space requirements.
static intAUTO_RESIZE_NEXT_COLUMN
When resizing column i, automatically change only the single column i+1 to provide or absorb excess space requirements.
static intAUTO_RESIZE_OFF
When resizing columns, do not automatically change any columns.
static intAUTO_RESIZE_SUBSEQUENT_COLUMNS
When resizing column i in a table of n columns, automatically change all columns in the range [i+1, n), uniformly, to provide or absorb excess space requirements.
protected booleanautoCreateColumnsFromModel
Whether or not the table should automatically compute a matching {@link TableColumnModel} and assign it to the {@link #columnModel} property when the {@link #dataModel} property is changed.
protected intautoResizeMode
A numeric code specifying the resizing behavior of the table.
protected TableCellEditorcellEditor
The current cell editor.
protected booleancellSelectionEnabled
Obsolete.
protected TableColumnModelcolumnModel

A model of various aspects of the columns of the table, not including the data stored in them.

protected TableModeldataModel
The model for data stored in the table.
protected HashtabledefaultEditorsByColumnClass
A table mapping {@link java.lang.Class} objects to {@link TableCellEditor} objects.
protected HashtabledefaultRenderersByColumnClass
A table mapping {@link java.lang.Class} objects to {@link TableCellEditor} objects.
protected inteditingColumn
The column that is edited, -1 if the table is not edited currently.
protected inteditingRow
The row that is edited, -1 if the table is not edited currently.
protected ComponenteditorComp
The component that is used for editing.
protected ColorgridColor
The color to paint the grid lines of the table, when either {@link #showHorizontalLines} or {@link #showVerticalLines} is set.
protected DimensionpreferredViewportSize
The size this table would prefer its viewport assume, if it is contained in a {@link JScrollPane}.
protected introwHeight
The height in pixels of any row of the table.
protected introwMargin
The height in pixels of the gap left between any two rows of the table.
protected booleanrowSelectionAllowed
Whether or not the table should allow row selection.
protected ColorselectionBackground
The color to paint the background of selected cells.
protected ColorselectionForeground
The color to paint the foreground of selected cells.
protected ListSelectionModelselectionModel
A model of the rows of this table which are currently selected.
protected booleanshowHorizontalLines
The showHorizontalLines property.
protected booleanshowVerticalLines
The showVerticalLines property.
protected JTableHeadertableHeader
The tableHeader property.
Constructor Summary
JTable()
Creates a new JTable instance.
JTable(int numRows, int numColumns)
Creates a new JTable instance with the given number of rows and columns.
JTable(Object[][] data, Object[] columnNames)
Creates a new JTable instance, storing the given data array and heaving the given column names.
JTable(TableModel model)
Creates a new JTable instance, using the given data model object that provides information about the table content.
JTable(TableModel dm, TableColumnModel cm)
Creates a new JTable instance, using the given model object that provides information about the table content.
JTable(TableModel dm, TableColumnModel cm, ListSelectionModel sm)
Creates a new JTable instance, providing data model, column model and list selection model.
JTable(Vector data, Vector columnNames)
Creates a new JTable instance that uses data and column names, stored in {@link Vector}s.
Method Summary
voidaddColumn(TableColumn column)
Add the new table column.
voidaddColumnSelectionInterval(int index0, int index1)
voidaddNotify()
voidaddRowSelectionInterval(int index0, int index1)
voidchangeSelection(int rowIndex, int columnIndex, boolean toggle, boolean extend)
voidclearSelection()
voidcolumnAdded(TableColumnModelEvent event)
Invoked when the column is added.
intcolumnAtPoint(Point point)
Returns index of the column that contains specified point or -1 if this table doesn't contain this point.
voidcolumnMarginChanged(ChangeEvent event)
Invoked when the column margin is changed.
voidcolumnMoved(TableColumnModelEvent event)
Invoked when the column is moved.
voidcolumnRemoved(TableColumnModelEvent event)
Invoked when the column is removed.
voidcolumnSelectionChanged(ListSelectionEvent event)
Invoked when the the column selection changes, repaints the changed columns.
protected voidconfigureEnclosingScrollPane()
intconvertColumnIndexToModel(int vc)
Convert the table model index into the table column number.
intconvertColumnIndexToView(int mc)
Convert the table column number to the table column model index.
protected TableColumnModelcreateDefaultColumnModel()
Create the default table column model that is used if the user-defined column model is not provided.
voidcreateDefaultColumnsFromModel()
Clears any existing columns from the JTable's {@link TableColumnModel} and creates new columns to match the values in the data ({@link TableModel}) used by the table.
protected TableModelcreateDefaultDataModel()
Create the default table data model that is used if the user-defined data model is not provided.
protected voidcreateDefaultEditors()
Create the default editors for this table.
protected voidcreateDefaultRenderers()
Create the default renderers for this table.
protected ListSelectionModelcreateDefaultSelectionModel()
Create the default table selection model that is used if the user-defined selection model is not provided.
protected JTableHeadercreateDefaultTableHeader()
Create the default table header, if the user - defined table header is not provided.
static JScrollPanecreateScrollPaneForTable(JTable table)
voiddoLayout()
Set the widths of all columns, taking they preferred widths into consideration.
booleaneditCellAt(int row, int column)
Programmatically starts editing the specified cell.
booleaneditCellAt(int row, int column, EventObject e)
Programmatically starts editing the specified cell.
voideditingCanceled(ChangeEvent event)
Invoked when the editing is cancelled.
voideditingStopped(ChangeEvent event)
Finish the current editing session and update the table with the new value by calling {@link #setValueAt}.
AccessibleContextgetAccessibleContext()
Get the value of the {@link #accessibleContext} property.
booleangetAutoCreateColumnsFromModel()
Get the value of the {@link #autoCreateColumnsFromModel} property.
intgetAutoResizeMode()
Get the value of the {@link #autoResizeMode} property.
TableCellEditorgetCellEditor(int row, int column)
Get the cell editor, suitable for editing the given cell.
TableCellEditorgetCellEditor()
Get the value of the {@link #cellEditor} property.
RectanglegetCellRect(int row, int column, boolean includeSpacing)
Calculate the visible rectangle for a particular row and column.
TableCellRenderergetCellRenderer(int row, int column)
Get the cell renderer for rendering the given cell.
booleangetCellSelectionEnabled()
Get the value of the {@link #cellSelectionEnabled} property.
TableColumngetColumn(Object identifier)
Get table column with the given identified.
Class<?>getColumnClass(int column)
Get the class (datatype) of the column.
intgetColumnCount()
Get the value of the columnCount property by delegation to the {@link #columnModel} field.
TableColumnModelgetColumnModel()
Get the value of the {@link #columnModel} property.
StringgetColumnName(int column)
Get the name of the column.
booleangetColumnSelectionAllowed()
Get the value of the columnSelectionAllowed property.
TableCellEditorgetDefaultEditor(Class<?> columnClass)
Get the default editor for editing values of the given type (String, Boolean and so on).
TableCellRenderergetDefaultRenderer(Class<?> columnClass)
Get the default renderer for rendering the given data type.
booleangetDragEnabled()
Get the value of the {@link #dragEnabled} property.
intgetEditingColumn()
Get the column, currently being edited
intgetEditingRow()
Get the row currently being edited.
ComponentgetEditorComponent()
Get the editor component that is currently editing one of the cells
ColorgetGridColor()
Get the value of the {@link #gridColor} property.
DimensiongetIntercellSpacing()
Get the value of the intercellSpacing property.
TableModelgetModel()
Get the value of the {@link #dataModel} property.
DimensiongetPreferredScrollableViewportSize()
Get the value of the {@link #preferredViewportSize} property.
intgetRowCount()
Get the value of the rowCount property by delegation to the {@link #dataModel} field.
intgetRowHeight()
Get the value of the {@link #rowHeight} property.
intgetRowHeight(int row)
Get the height of the specified row.
intgetRowMargin()
Get the value of the {@link #rowMargin} property.
booleangetRowSelectionAllowed()
Get the value of the {@link #rowSelectionAllowed} property.
intgetScrollableBlockIncrement(Rectangle visibleRect, int orientation, int direction)
booleangetScrollableTracksViewportHeight()
Get the value of the scrollableTracksViewportHeight property.
booleangetScrollableTracksViewportWidth()
Get the value of the scrollableTracksViewportWidth property.
intgetScrollableUnitIncrement(Rectangle visibleRect, int orientation, int direction)
Return the preferred scrolling amount (in pixels) for the given scrolling direction and orientation.
intgetSelectedColumn()
Get the value of the selectedColumn property by delegation to the {@link #columnModel} field.
intgetSelectedColumnCount()
Get the value of the selectedColumnCount property by delegation to the {@link #columnModel} field.
int[]getSelectedColumns()
Get the value of the selectedColumns property by delegation to the {@link #columnModel} field.
intgetSelectedRow()
Get the value of the selectedRow property by delegation to the {@link ListSelectionModel#getMinSelectionIndex} method of the {@link #selectionModel} field.
intgetSelectedRowCount()
Get the value of the selectedRowCount property by delegation to the {@link #selectionModel} field.
int[]getSelectedRows()
Get the value of the selectedRows property by delegation to the {@link #selectionModel} field.
ColorgetSelectionBackground()
Get the value of the {@link #selectionBackground} property.
ColorgetSelectionForeground()
Get the value of the {@link #selectionForeground} property.
ListSelectionModelgetSelectionModel()
Get the value of the {@link #selectionModel} property.
booleangetShowHorizontalLines()
Get the value of the {@link #showHorizontalLines} property.
booleangetShowVerticalLines()
Get the value of the {@link #showVerticalLines} property.
booleangetSurrendersFocusOnKeystroke()
Returns whether cell editors of this table should receive keyboard focus when the editor is activated by a keystroke.
JTableHeadergetTableHeader()
Get the value of the {@link #tableHeader} property.
TableUIgetUI()
This method returns the table's UI delegate.
StringgetUIClassID()
ObjectgetValueAt(int row, int column)
Get the cell value at the given position.
protected voidinitializeLocalVars()
Initialize local variables to default values.
booleanisCellEditable(int row, int column)
Returns true if the specified cell is editable, and false otherwise.
booleanisCellSelected(int row, int column)
Checks if the given cell is selected.
booleanisColumnSelected(int column)
Checks if the given column is selected.
booleanisEditing()
Check if one of the table cells is currently being edited.
booleanisRowSelected(int row)
Checks if the given row is selected.
voidmoveColumn(int column, int targetColumn)
Moves column at the specified index to new given location.
ComponentprepareEditor(TableCellEditor editor, int row, int column)
Prepares the editor by querying for the value and selection state of the cell at (row, column).
ComponentprepareRenderer(TableCellRenderer renderer, int row, int column)
Prepare the renderer for rendering the given cell.
voidremoveColumn(TableColumn column)
Removes specified column from displayable columns of this table.
voidremoveColumnSelectionInterval(int index0, int index1)
voidremoveEditor()
Discards the editor object.
voidremoveNotify()
voidremoveRowSelectionInterval(int index0, int index1)
protected voidresizeAndRepaint()
This revalidates the JTable and queues a repaint.
introwAtPoint(Point point)
Returns index of the row that contains specified point or -1 if this table doesn't contain this point.
voidselectAll()
Select all table.
voidsetAutoCreateColumnsFromModel(boolean autoCreate)
Set the value of the {@link #autoCreateColumnsFromModel} flag.
voidsetAutoResizeMode(int a)
Set the value of the {@link #autoResizeMode} property.
voidsetCellEditor(TableCellEditor c)

Set the value of the {@link #cellEditor} property.

Unregister this as a {@link CellEditorListener} from previous {@link #cellEditor} and register it with new parameter c.

voidsetCellSelectionEnabled(boolean c)
Set the value of the {@link #cellSelectionEnabled} property.
voidsetColumnModel(TableColumnModel c)

Set the value of the {@link #columnModel} property.

Unregister this as a {@link TableColumnModelListener} from previous {@link #columnModel} and register it with new parameter c.

voidsetColumnSelectionAllowed(boolean c)
Set the value of the columnSelectionAllowed property.
voidsetColumnSelectionInterval(int index0, int index1)
voidsetDefaultEditor(Class<?> columnClass, TableCellEditor editor)
Set the default editor for the given column class (column data type).
voidsetDefaultRenderer(Class<?> columnClass, TableCellRenderer rend)
Set default renderer for rendering the given data type.
voidsetDragEnabled(boolean d)
Set the value of the {@link #dragEnabled} property.
voidsetEditingColumn(int column)
Set the column, currently being edited
voidsetEditingRow(int row)
Set the row currently being edited.
voidsetGridColor(Color g)
Set the value of the {@link #gridColor} property.
voidsetIntercellSpacing(Dimension i)
Set the value of the intercellSpacing property.
voidsetModel(TableModel m)

Set the value of the {@link #dataModel} property.

Unregister this as a {@link TableModelListener} from previous {@link #dataModel} and register it with new parameter m.

voidsetPreferredScrollableViewportSize(Dimension p)
Set the value of the {@link #preferredViewportSize} property.
voidsetRowHeight(int r)
Sets the height for all rows in the table.
voidsetRowHeight(int row, int rh)
Sets the height of a single row in the table.
voidsetRowMargin(int r)
Set the value of the {@link #rowMargin} property.
voidsetRowSelectionAllowed(boolean r)
Set the value of the {@link #rowSelectionAllowed} property.
voidsetRowSelectionInterval(int index0, int index1)
voidsetSelectionBackground(Color s)

Set the value of the {@link #selectionBackground} property.

Fire a PropertyChangeEvent with name {@link #SELECTION_BACKGROUND_CHANGED_PROPERTY} to registered listeners, if selectionBackground changed.

voidsetSelectionForeground(Color s)

Set the value of the {@link #selectionForeground} property.

Fire a PropertyChangeEvent with name {@link #SELECTION_FOREGROUND_CHANGED_PROPERTY} to registered listeners, if selectionForeground changed.

voidsetSelectionMode(int s)
Set the value of the selectionMode property by delegation to the {@link #selectionModel} field.
voidsetSelectionModel(ListSelectionModel s)

Set the value of the {@link #selectionModel} property.

Unregister this as a {@link ListSelectionListener} from previous {@link #selectionModel} and register it with new parameter s.

voidsetShowGrid(boolean s)
Set the value of the showGrid property.
voidsetShowHorizontalLines(boolean s)
Set the value of the {@link #showHorizontalLines} property.
voidsetShowVerticalLines(boolean s)
Set the value of the {@link #showVerticalLines} property.
voidsetSurrendersFocusOnKeystroke(boolean value)
Sets whether cell editors of this table should receive keyboard focus when the editor is activated by a keystroke.
voidsetTableHeader(JTableHeader t)
Set the value of the {@link #tableHeader} property.
voidsetUI(TableUI ui)
This method sets the table's UI delegate.
voidsetValueAt(Object value, int row, int column)
Set value for the cell at the given position.
voidsizeColumnsToFit(boolean lastColumnOnly)
voidsizeColumnsToFit(int resizingColumn)
Obsolete since JDK 1.4.
voidtableChanged(TableModelEvent event)
Invoked when the table changes.
protected voidunconfigureEnclosingScrollPane()
voidupdateUI()
voidvalueChanged(ListSelectionEvent event)
Invoked when another table row is selected.

Field Detail

AUTO_RESIZE_ALL_COLUMNS

public static final int AUTO_RESIZE_ALL_COLUMNS
When resizing column i in a table of n columns, automatically change all columns in the range [0, n) (with the exception of column i) uniformly, to provide or absorb excess space requirements.

AUTO_RESIZE_LAST_COLUMN

public static final int AUTO_RESIZE_LAST_COLUMN
When resizing column i in a table of n columns, automatically change column n-1 (the last column in the table) to provide or absorb excess space requirements.

AUTO_RESIZE_NEXT_COLUMN

public static final int AUTO_RESIZE_NEXT_COLUMN
When resizing column i, automatically change only the single column i+1 to provide or absorb excess space requirements.

AUTO_RESIZE_OFF

public static final int AUTO_RESIZE_OFF
When resizing columns, do not automatically change any columns. In this case the table should be enclosed in a {@link JScrollPane} in order to accomodate cases in which the table size exceeds its visible area.

AUTO_RESIZE_SUBSEQUENT_COLUMNS

public static final int AUTO_RESIZE_SUBSEQUENT_COLUMNS
When resizing column i in a table of n columns, automatically change all columns in the range [i+1, n), uniformly, to provide or absorb excess space requirements.

autoCreateColumnsFromModel

protected boolean autoCreateColumnsFromModel
Whether or not the table should automatically compute a matching {@link TableColumnModel} and assign it to the {@link #columnModel} property when the {@link #dataModel} property is changed.

See Also: setModel createDefaultColumnsFromModel setColumnModel JTable getAutoCreateColumnsFromModel

autoResizeMode

protected int autoResizeMode
A numeric code specifying the resizing behavior of the table. Must be one of {@link #AUTO_RESIZE_ALL_COLUMNS} (the default), {@link #AUTO_RESIZE_LAST_COLUMN}, {@link #AUTO_RESIZE_NEXT_COLUMN}, {@link #AUTO_RESIZE_SUBSEQUENT_COLUMNS}, or {@link #AUTO_RESIZE_OFF}.

See Also: doLayout JTable getAutoResizeMode

cellEditor

protected TableCellEditor cellEditor
The current cell editor.

cellSelectionEnabled

protected boolean cellSelectionEnabled
Obsolete. Use {@link #rowSelectionAllowed}, {@link #getColumnSelectionAllowed}, or the combined methods {@link #getCellSelectionEnabled} and {@link #setCellSelectionEnabled(boolean)}.

columnModel

protected TableColumnModel columnModel

A model of various aspects of the columns of the table, not including the data stored in them. The {@link TableColumnModel} is principally concerned with holding a set of {@link TableColumn} objects, each of which describes the display parameters of a column and the numeric index of the column from the data model which the column is presenting.

The TableColumnModel also contains a {@link ListSelectionModel} which indicates which columns are currently selected. This selection model works in combination with the {@link #selectionModel} of the table itself to specify a table selection: a combination of row and column selections.

Most application programmers do not need to work with this property at all: setting {@link #autoCreateColumnsFromModel} will construct the columnModel automatically, and the table acts as a facade for most of the interesting properties of the columnModel anyways.

See Also: setColumnModel getColumnModel

dataModel

protected TableModel dataModel
The model for data stored in the table. Confusingly, the published API requires that this field be called dataModel, despite its property name. The table listens to its model as a {@link TableModelListener}.

See Also: tableChanged addTableModelListener

defaultEditorsByColumnClass

protected Hashtable defaultEditorsByColumnClass
A table mapping {@link java.lang.Class} objects to {@link TableCellEditor} objects. This table is consulted by the FIXME

defaultRenderersByColumnClass

protected Hashtable defaultRenderersByColumnClass
A table mapping {@link java.lang.Class} objects to {@link TableCellEditor} objects. This table is consulted by the FIXME

editingColumn

protected int editingColumn
The column that is edited, -1 if the table is not edited currently.

editingRow

protected int editingRow
The row that is edited, -1 if the table is not edited currently.

editorComp

protected transient Component editorComp
The component that is used for editing. null if the table is not editing currently.

gridColor

protected Color gridColor
The color to paint the grid lines of the table, when either {@link #showHorizontalLines} or {@link #showVerticalLines} is set.

See Also: setGridColor getGridColor

preferredViewportSize

protected Dimension preferredViewportSize
The size this table would prefer its viewport assume, if it is contained in a {@link JScrollPane}.

See Also: setPreferredScrollableViewportSize getPreferredScrollableViewportSize

rowHeight

protected int rowHeight
The height in pixels of any row of the table. All rows in a table are of uniform height. This differs from column width, which varies on a per-column basis, and is stored in the individual columns of the {@link #columnModel}.

See Also: getRowHeight JTable getWidth TableColumn

rowMargin

protected int rowMargin
The height in pixels of the gap left between any two rows of the table.

See Also: JTable getRowHeight getIntercellSpacing setIntercellSpacing getColumnMargin TableColumnModel

rowSelectionAllowed

protected boolean rowSelectionAllowed
Whether or not the table should allow row selection. If the table allows both row and column selection, it is said to allow "cell selection". Previous versions of the JDK supported cell selection as an independent concept, but it is now represented solely in terms of simultaneous row and column selection.

See Also: getColumnSelectionAllowed JTable getRowSelectionAllowed getCellSelectionEnabled JTable

selectionBackground

protected Color selectionBackground
The color to paint the background of selected cells. Fires a property change event with name {@link #SELECTION_BACKGROUND_CHANGED_PROPERTY} when its value changes.

See Also: setSelectionBackground getSelectionBackground

selectionForeground

protected Color selectionForeground
The color to paint the foreground of selected cells. Fires a property change event with name {@link #SELECTION_FOREGROUND_CHANGED_PROPERTY} when its value changes.

See Also: setSelectionForeground getSelectionForeground

selectionModel

protected ListSelectionModel selectionModel
A model of the rows of this table which are currently selected. This model is used in combination with the column selection model held as a member of the {@link #columnModel} property, to represent the rows and columns (or both: cells) of the table which are currently selected.

See Also: rowSelectionAllowed setSelectionModel getSelectionModel getSelectionModel addListSelectionListener

showHorizontalLines

protected boolean showHorizontalLines
The showHorizontalLines property.

showVerticalLines

protected boolean showVerticalLines
The showVerticalLines property.

tableHeader

protected JTableHeader tableHeader
The tableHeader property.

Constructor Detail

JTable

public JTable()
Creates a new JTable instance.

JTable

public JTable(int numRows, int numColumns)
Creates a new JTable instance with the given number of rows and columns.

Parameters: numRows an int value numColumns an int value

JTable

public JTable(Object[][] data, Object[] columnNames)
Creates a new JTable instance, storing the given data array and heaving the given column names. To see the column names, you must place the JTable into the {@link JScrollPane}.

Parameters: data an Object[][] the table data columnNames an Object[] the column headers

JTable

public JTable(TableModel model)
Creates a new JTable instance, using the given data model object that provides information about the table content. The table model object is asked for the table size, other features and also receives notifications in the case when the table has been edited by the user.

Parameters: model the table model.

JTable

public JTable(TableModel dm, TableColumnModel cm)
Creates a new JTable instance, using the given model object that provides information about the table content. The table data model object is asked for the table size, other features and also receives notifications in the case when the table has been edited by the user. The table column model provides more detailed control on the table column related features.

Parameters: dm the table data mode cm the table column model

JTable

public JTable(TableModel dm, TableColumnModel cm, ListSelectionModel sm)
Creates a new JTable instance, providing data model, column model and list selection model. The list selection model manages the selections.

Parameters: dm data model (manages table data) cm column model (manages table columns) sm list selection model (manages table selections)

JTable

public JTable(Vector data, Vector columnNames)
Creates a new JTable instance that uses data and column names, stored in {@link Vector}s.

Parameters: data the table data columnNames the table column names.

Method Detail

addColumn

public void addColumn(TableColumn column)
Add the new table column. The table column class allows to specify column features more precisely, setting the preferred width, column data type (column class) and table headers. There is no need the add columns to the table if the default column handling is sufficient.

Parameters: column the new column to add.

addColumnSelectionInterval

public void addColumnSelectionInterval(int index0, int index1)

addNotify

public void addNotify()

addRowSelectionInterval

public void addRowSelectionInterval(int index0, int index1)

changeSelection

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

clearSelection

public void clearSelection()

columnAdded

public void columnAdded(TableColumnModelEvent event)
Invoked when the column is added. Revalidates and repains the table.

columnAtPoint

public int columnAtPoint(Point point)
Returns index of the column that contains specified point or -1 if this table doesn't contain this point.

Parameters: point point to identify the column

Returns: index of the column that contains specified point or -1 if this table doesn't contain this point.

columnMarginChanged

public void columnMarginChanged(ChangeEvent event)
Invoked when the column margin is changed. Revalidates and repains the table.

columnMoved

public void columnMoved(TableColumnModelEvent event)
Invoked when the column is moved. Revalidates and repains the table.

columnRemoved

public void columnRemoved(TableColumnModelEvent event)
Invoked when the column is removed. Revalidates and repains the table.

columnSelectionChanged

public void columnSelectionChanged(ListSelectionEvent event)
Invoked when the the column selection changes, repaints the changed columns. It is not recommended to override this method, register the listener instead.

configureEnclosingScrollPane

protected void configureEnclosingScrollPane()

convertColumnIndexToModel

public int convertColumnIndexToModel(int vc)
Convert the table model index into the table column number. The model number need not match the real column position. The columns may be rearranged by the user with mouse at any time by dragging the column headers.

Parameters: vc the column number (0=first).

Returns: the table column model index of this column.

See Also: getModelIndex

convertColumnIndexToView

public int convertColumnIndexToView(int mc)
Convert the table column number to the table column model index. The model number need not match the real column position. The columns may be rearranged by the user with mouse at any time by dragging the column headers.

Parameters: mc the table column index (0=first).

Returns: the table column number in the model

See Also: getModelIndex

createDefaultColumnModel

protected TableColumnModel createDefaultColumnModel()
Create the default table column model that is used if the user-defined column model is not provided. The default method creates {@link DefaultTableColumnModel}.

Returns: the created table column model.

createDefaultColumnsFromModel

public void createDefaultColumnsFromModel()
Clears any existing columns from the JTable's {@link TableColumnModel} and creates new columns to match the values in the data ({@link TableModel}) used by the table.

See Also: JTable

createDefaultDataModel

protected TableModel createDefaultDataModel()
Create the default table data model that is used if the user-defined data model is not provided. The default method creates {@link DefaultTableModel}.

Returns: the created table data model.

createDefaultEditors

protected void createDefaultEditors()
Create the default editors for this table. The default method creates the editor for Booleans. Other fields are edited as strings at the moment.

createDefaultRenderers

protected void createDefaultRenderers()
Create the default renderers for this table. The default method creates renderers for Boolean, Number, Double, Date, Icon and ImageIcon.

createDefaultSelectionModel

protected ListSelectionModel createDefaultSelectionModel()
Create the default table selection model that is used if the user-defined selection model is not provided. The default method creates {@link DefaultListSelectionModel}.

Returns: the created table data model.

createDefaultTableHeader

protected JTableHeader createDefaultTableHeader()
Create the default table header, if the user - defined table header is not provided.

Returns: the default table header.

createScrollPaneForTable

public static JScrollPane createScrollPaneForTable(JTable table)

Deprecated: 1.0.2, replaced by new JScrollPane(JTable)

doLayout

public void doLayout()
Set the widths of all columns, taking they preferred widths into consideration. The excess space, if any, will be distrubuted between all columns. This method also handles special cases when one of the collumns is currently being resized.

See Also: TableColumn

editCellAt

public boolean editCellAt(int row, int column)
Programmatically starts editing the specified cell.

Parameters: row the row of the cell to edit. column the column of the cell to edit.

editCellAt

public boolean editCellAt(int row, int column, EventObject e)
Programmatically starts editing the specified cell.

Parameters: row the row of the cell to edit. column the column of the cell to edit.

editingCanceled

public void editingCanceled(ChangeEvent event)
Invoked when the editing is cancelled.

editingStopped

public void editingStopped(ChangeEvent event)
Finish the current editing session and update the table with the new value by calling {@link #setValueAt}.

Parameters: event the change event

getAccessibleContext

public AccessibleContext getAccessibleContext()
Get the value of the {@link #accessibleContext} property.

Returns: The current value of the property

getAutoCreateColumnsFromModel

public boolean getAutoCreateColumnsFromModel()
Get the value of the {@link #autoCreateColumnsFromModel} property.

Returns: The current value of the property

getAutoResizeMode

public int getAutoResizeMode()
Get the value of the {@link #autoResizeMode} property.

Returns: The current value of the property

getCellEditor

public TableCellEditor getCellEditor(int row, int column)
Get the cell editor, suitable for editing the given cell. The default method requests the editor from the column model. If the column model does not provide the editor, the call is forwarded to the {@link #getDefaultEditor(Class)} with the parameter, obtained from {@link TableModel#getColumnClass(int)}.

Parameters: row the cell row column the cell column

Returns: the editor to edit that cell

getCellEditor

public TableCellEditor getCellEditor()
Get the value of the {@link #cellEditor} property.

Returns: The current value of the property

getCellRect

public Rectangle getCellRect(int row, int column, boolean includeSpacing)
Calculate the visible rectangle for a particular row and column. The row and column are specified in visual terms; the column may not match the {@link #dataModel} column.

Parameters: row the visible row to get the cell rectangle of column the visible column to get the cell rectangle of, which may differ from the {@link #dataModel} column includeSpacing whether or not to include the cell margins in the resulting cell. If false, the result will only contain the inner area of the target cell, not including its margins.

Returns: a rectangle enclosing the specified cell

getCellRenderer

public TableCellRenderer getCellRenderer(int row, int column)
Get the cell renderer for rendering the given cell.

Parameters: row the cell row column the cell column

Returns: the cell renderer to render that cell.

getCellSelectionEnabled

public boolean getCellSelectionEnabled()
Get the value of the {@link #cellSelectionEnabled} property.

Returns: The current value of the property

getColumn

public TableColumn getColumn(Object identifier)
Get table column with the given identified.

Parameters: identifier the column identifier

Returns: the table column with this identifier

Throws: IllegalArgumentException if identifier is null or there is no column with that identifier.

See Also: setIdentifier

getColumnClass

public Class<?> getColumnClass(int column)
Get the class (datatype) of the column. The cells are rendered and edited differently, depending from they data type.

Parameters: column the column (not the model index).

Returns: the class, defining data type of that column (String.class for String, Boolean.class for boolean and so on).

getColumnCount

public int getColumnCount()
Get the value of the columnCount property by delegation to the {@link #columnModel} field.

Returns: The current value of the columnCount property

getColumnModel

public TableColumnModel getColumnModel()
Get the value of the {@link #columnModel} property.

Returns: The current value of the property

getColumnName

public String getColumnName(int column)
Get the name of the column. If the column has the column identifier set, the return value is the result of the .toString() method call on that identifier. If the identifier is not explicitly set, the returned value is calculated by {@link javax.swing.table.AbstractTableModel#getColumnName(int)}.

Parameters: column the column

Returns: the name of that column.

getColumnSelectionAllowed

public boolean getColumnSelectionAllowed()
Get the value of the columnSelectionAllowed property.

Returns: The current value of the columnSelectionAllowed property

See Also: JTable

getDefaultEditor

public TableCellEditor getDefaultEditor(Class<?> columnClass)
Get the default editor for editing values of the given type (String, Boolean and so on).

Parameters: columnClass the class of the value that will be edited.

Returns: the editor, suitable for editing this data type

getDefaultRenderer

public TableCellRenderer getDefaultRenderer(Class<?> columnClass)
Get the default renderer for rendering the given data type.

Parameters: columnClass the data that must be rendered

Returns: the appropriate defauld renderer for rendering that data type.

getDragEnabled

public boolean getDragEnabled()
Get the value of the {@link #dragEnabled} property.

Returns: The current value of the property

getEditingColumn

public int getEditingColumn()
Get the column, currently being edited

Returns: the column, currently being edited.

getEditingRow

public int getEditingRow()
Get the row currently being edited.

Returns: the row, currently being edited.

getEditorComponent

public Component getEditorComponent()
Get the editor component that is currently editing one of the cells

Returns: the editor component or null, if none of the cells is being edited.

getGridColor

public Color getGridColor()
Get the value of the {@link #gridColor} property.

Returns: The current value of the property

getIntercellSpacing

public Dimension getIntercellSpacing()
Get the value of the intercellSpacing property.

Returns: The current value of the property

getModel

public TableModel getModel()
Get the value of the {@link #dataModel} property.

Returns: The current value of the property

getPreferredScrollableViewportSize

public Dimension getPreferredScrollableViewportSize()
Get the value of the {@link #preferredViewportSize} property.

Returns: The current value of the property

getRowCount

public int getRowCount()
Get the value of the rowCount property by delegation to the {@link #dataModel} field.

Returns: The current value of the rowCount property

getRowHeight

public int getRowHeight()
Get the value of the {@link #rowHeight} property.

Returns: The current value of the property

getRowHeight

public int getRowHeight(int row)
Get the height of the specified row.

Parameters: row the row whose height to return

getRowMargin

public int getRowMargin()
Get the value of the {@link #rowMargin} property.

Returns: The current value of the property

getRowSelectionAllowed

public boolean getRowSelectionAllowed()
Get the value of the {@link #rowSelectionAllowed} property.

Returns: The current value of the property

See Also: JTable

getScrollableBlockIncrement

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

getScrollableTracksViewportHeight

public boolean getScrollableTracksViewportHeight()
Get the value of the scrollableTracksViewportHeight property.

Returns: The constant value false

getScrollableTracksViewportWidth

public boolean getScrollableTracksViewportWidth()
Get the value of the scrollableTracksViewportWidth property.

Returns: true unless the {@link #autoResizeMode} property is AUTO_RESIZE_OFF

getScrollableUnitIncrement

public int getScrollableUnitIncrement(Rectangle visibleRect, int orientation, int direction)
Return the preferred scrolling amount (in pixels) for the given scrolling direction and orientation. This method handles a partially exposed row by returning the distance required to completely expose the item. When scrolling the top item is completely exposed.

Parameters: visibleRect the currently visible part of the component. orientation the scrolling orientation direction the scrolling direction (negative - up, positive -down). The values greater than one means that more mouse wheel or similar events were generated, and hence it is better to scroll the longer distance.

getSelectedColumn

public int getSelectedColumn()
Get the value of the selectedColumn property by delegation to the {@link #columnModel} field.

Returns: The current value of the selectedColumn property

getSelectedColumnCount

public int getSelectedColumnCount()
Get the value of the selectedColumnCount property by delegation to the {@link #columnModel} field.

Returns: The current value of the selectedColumnCount property

getSelectedColumns

public int[] getSelectedColumns()
Get the value of the selectedColumns property by delegation to the {@link #columnModel} field.

Returns: The current value of the selectedColumns property

getSelectedRow

public int getSelectedRow()
Get the value of the selectedRow property by delegation to the {@link ListSelectionModel#getMinSelectionIndex} method of the {@link #selectionModel} field.

Returns: The current value of the selectedRow property

getSelectedRowCount

public int getSelectedRowCount()
Get the value of the selectedRowCount property by delegation to the {@link #selectionModel} field.

Returns: The current value of the selectedRowCount property

getSelectedRows

public int[] getSelectedRows()
Get the value of the selectedRows property by delegation to the {@link #selectionModel} field.

Returns: The current value of the selectedRows property

getSelectionBackground

public Color getSelectionBackground()
Get the value of the {@link #selectionBackground} property.

Returns: The current value of the property

getSelectionForeground

public Color getSelectionForeground()
Get the value of the {@link #selectionForeground} property.

Returns: The current value of the property

getSelectionModel

public ListSelectionModel getSelectionModel()
Get the value of the {@link #selectionModel} property.

Returns: The current value of the property

getShowHorizontalLines

public boolean getShowHorizontalLines()
Get the value of the {@link #showHorizontalLines} property.

Returns: The current value of the property

getShowVerticalLines

public boolean getShowVerticalLines()
Get the value of the {@link #showVerticalLines} property.

Returns: The current value of the property

getSurrendersFocusOnKeystroke

public boolean getSurrendersFocusOnKeystroke()
Returns whether cell editors of this table should receive keyboard focus when the editor is activated by a keystroke. The default setting is false which means that the table should keep the keyboard focus until the cell is selected by a mouse click.

Returns: whether cell editors of this table should receive keyboard focus when the editor is activated by a keystroke

Since: 1.4

getTableHeader

public JTableHeader getTableHeader()
Get the value of the {@link #tableHeader} property.

Returns: The current value of the property

getUI

public TableUI getUI()
This method returns the table's UI delegate.

Returns: The table's UI delegate.

getUIClassID

public String getUIClassID()

getValueAt

public Object getValueAt(int row, int column)
Get the cell value at the given position.

Parameters: row the row to get the value column the actual column number (not the model index) to get the value.

Returns: the cell value, as returned by model.

initializeLocalVars

protected void initializeLocalVars()
Initialize local variables to default values.

isCellEditable

public boolean isCellEditable(int row, int column)
Returns true if the specified cell is editable, and false otherwise.

Parameters: row the row index. column the column index.

Returns: true if the cell is editable, false otherwise.

isCellSelected

public boolean isCellSelected(int row, int column)
Checks if the given cell is selected. The cell is selected if both the cell row and the cell column are selected.

Parameters: row the cell row column the cell column

Returns: true if the cell is selected, false otherwise

isColumnSelected

public boolean isColumnSelected(int column)
Checks if the given column is selected.

Parameters: column the column

Returns: true if the column is selected (as reported by the selection model, associated with the column model), false otherwise.

isEditing

public boolean isEditing()
Check if one of the table cells is currently being edited.

Returns: true if there is a cell being edited.

isRowSelected

public boolean isRowSelected(int row)
Checks if the given row is selected.

Parameters: row the row

Returns: true if the row is selected (as reported by the selection model), false otherwise.

moveColumn

public void moveColumn(int column, int targetColumn)
Moves column at the specified index to new given location.

Parameters: column index of the column to move targetColumn index specifying new location of the column

prepareEditor

public Component prepareEditor(TableCellEditor editor, int row, int column)
Prepares the editor by querying for the value and selection state of the cell at (row, column).

Parameters: editor the TableCellEditor to set up row the row of the cell to edit column the column of the cell to edit

Returns: the Component being edited

prepareRenderer

public Component prepareRenderer(TableCellRenderer renderer, int row, int column)
Prepare the renderer for rendering the given cell.

Parameters: renderer the renderer being prepared row the row of the cell being rendered column the column of the cell being rendered

Returns: the component which .paint() method will paint the cell.

removeColumn

public void removeColumn(TableColumn column)
Removes specified column from displayable columns of this table.

Parameters: column column to removed

removeColumnSelectionInterval

public void removeColumnSelectionInterval(int index0, int index1)

removeEditor

public void removeEditor()
Discards the editor object.

removeNotify

public void removeNotify()

removeRowSelectionInterval

public void removeRowSelectionInterval(int index0, int index1)

resizeAndRepaint

protected void resizeAndRepaint()
This revalidates the JTable and queues a repaint.

rowAtPoint

public int rowAtPoint(Point point)
Returns index of the row that contains specified point or -1 if this table doesn't contain this point.

Parameters: point point to identify the row

Returns: index of the row that contains specified point or -1 if this table doesn't contain this point.

selectAll

public void selectAll()
Select all table.

setAutoCreateColumnsFromModel

public void setAutoCreateColumnsFromModel(boolean autoCreate)
Set the value of the {@link #autoCreateColumnsFromModel} flag. If the flag changes from false to true, the {@link #createDefaultColumnsFromModel()} method is called.

Parameters: autoCreate the new value of the flag.

setAutoResizeMode

public void setAutoResizeMode(int a)
Set the value of the {@link #autoResizeMode} property.

Parameters: a The new value of the autoResizeMode property

setCellEditor

public void setCellEditor(TableCellEditor c)

Set the value of the {@link #cellEditor} property.

Unregister this as a {@link CellEditorListener} from previous {@link #cellEditor} and register it with new parameter c.

Parameters: c The new value of the cellEditor property

setCellSelectionEnabled

public void setCellSelectionEnabled(boolean c)
Set the value of the {@link #cellSelectionEnabled} property.

Parameters: c The new value of the cellSelectionEnabled property

setColumnModel

public void setColumnModel(TableColumnModel c)

Set the value of the {@link #columnModel} property.

Unregister this as a {@link TableColumnModelListener} from previous {@link #columnModel} and register it with new parameter c.

Parameters: c The new value of the columnModel property

setColumnSelectionAllowed

public void setColumnSelectionAllowed(boolean c)
Set the value of the columnSelectionAllowed property.

Parameters: c The new value of the property

See Also: getColumnSelectionAllowed

setColumnSelectionInterval

public void setColumnSelectionInterval(int index0, int index1)

setDefaultEditor

public void setDefaultEditor(Class<?> columnClass, TableCellEditor editor)
Set the default editor for the given column class (column data type). By default, String is handled by text field and Boolean is handled by the check box.

Parameters: columnClass the column data type editor the editor that will edit this data type

See Also: TableModel

setDefaultRenderer

public void setDefaultRenderer(Class<?> columnClass, TableCellRenderer rend)
Set default renderer for rendering the given data type.

Parameters: columnClass the data type (String, Boolean and so on) that must be rendered. rend the renderer that will rend this data type

setDragEnabled

public void setDragEnabled(boolean d)
Set the value of the {@link #dragEnabled} property.

Parameters: d The new value of the dragEnabled property

setEditingColumn

public void setEditingColumn(int column)
Set the column, currently being edited

Parameters: column the column, currently being edited.

setEditingRow

public void setEditingRow(int row)
Set the row currently being edited.

Parameters: row the row, that will be edited

setGridColor

public void setGridColor(Color g)
Set the value of the {@link #gridColor} property.

Parameters: g The new value of the gridColor property

setIntercellSpacing

public void setIntercellSpacing(Dimension i)
Set the value of the intercellSpacing property.

Parameters: i The new value of the intercellSpacing property

setModel

public void setModel(TableModel m)

Set the value of the {@link #dataModel} property.

Unregister this as a {@link TableModelListener} from previous {@link #dataModel} and register it with new parameter m.

Parameters: m The new value of the model property

setPreferredScrollableViewportSize

public void setPreferredScrollableViewportSize(Dimension p)
Set the value of the {@link #preferredViewportSize} property.

Parameters: p The new value of the preferredViewportSize property

setRowHeight

public void setRowHeight(int r)
Sets the height for all rows in the table. If you want to change the height of a single row instead, use {@link #setRowHeight(int, int)}.

Parameters: r the height to set for all rows

See Also: getRowHeight JTable JTable

setRowHeight

public void setRowHeight(int row, int rh)
Sets the height of a single row in the table.

Parameters: rh the new row height row the row to change the height of

setRowMargin

public void setRowMargin(int r)
Set the value of the {@link #rowMargin} property.

Parameters: r The new value of the rowMargin property

setRowSelectionAllowed

public void setRowSelectionAllowed(boolean r)
Set the value of the {@link #rowSelectionAllowed} property.

Parameters: r The new value of the rowSelectionAllowed property

See Also: getRowSelectionAllowed

setRowSelectionInterval

public void setRowSelectionInterval(int index0, int index1)

setSelectionBackground

public void setSelectionBackground(Color s)

Set the value of the {@link #selectionBackground} property.

Fire a PropertyChangeEvent with name {@link #SELECTION_BACKGROUND_CHANGED_PROPERTY} to registered listeners, if selectionBackground changed.

Parameters: s The new value of the selectionBackground property

setSelectionForeground

public void setSelectionForeground(Color s)

Set the value of the {@link #selectionForeground} property.

Fire a PropertyChangeEvent with name {@link #SELECTION_FOREGROUND_CHANGED_PROPERTY} to registered listeners, if selectionForeground changed.

Parameters: s The new value of the selectionForeground property

setSelectionMode

public void setSelectionMode(int s)
Set the value of the selectionMode property by delegation to the {@link #selectionModel} field. The same selection mode is set for row and column selection models.

Parameters: s The new value of the property

setSelectionModel

public void setSelectionModel(ListSelectionModel s)

Set the value of the {@link #selectionModel} property.

Unregister this as a {@link ListSelectionListener} from previous {@link #selectionModel} and register it with new parameter s.

Parameters: s The new value of the selectionModel property

setShowGrid

public void setShowGrid(boolean s)
Set the value of the showGrid property.

Parameters: s The new value of the showGrid property

setShowHorizontalLines

public void setShowHorizontalLines(boolean s)
Set the value of the {@link #showHorizontalLines} property.

Parameters: s The new value of the showHorizontalLines property

setShowVerticalLines

public void setShowVerticalLines(boolean s)
Set the value of the {@link #showVerticalLines} property.

Parameters: s The new value of the showVerticalLines property

setSurrendersFocusOnKeystroke

public void setSurrendersFocusOnKeystroke(boolean value)
Sets whether cell editors of this table should receive keyboard focus when the editor is activated by a keystroke. The default setting is false which means that the table should keep the keyboard focus until the cell is selected by a mouse click.

Parameters: value the value to set

Since: 1.4

setTableHeader

public void setTableHeader(JTableHeader t)
Set the value of the {@link #tableHeader} property.

Parameters: t The new value of the tableHeader property

setUI

public void setUI(TableUI ui)
This method sets the table's UI delegate.

Parameters: ui The table's UI delegate.

setValueAt

public void setValueAt(Object value, int row, int column)
Set value for the cell at the given position. The modified cell is repainted.

Parameters: value the value to set row the row of the cell being modified column the column of the cell being modified

sizeColumnsToFit

public void sizeColumnsToFit(boolean lastColumnOnly)

Deprecated: Replaced by doLayout()

sizeColumnsToFit

public void sizeColumnsToFit(int resizingColumn)
Obsolete since JDK 1.4. Please use doLayout().

tableChanged

public void tableChanged(TableModelEvent event)
Invoked when the table changes. null means everything changed.

unconfigureEnclosingScrollPane

protected void unconfigureEnclosingScrollPane()

updateUI

public void updateUI()

valueChanged

public void valueChanged(ListSelectionEvent event)
Invoked when another table row is selected. It is not recommended to override thid method, register the listener instead.