javax.swing

Class JTable

Implemented Interfaces:
Accessible, CellEditorListener, EventListener, ImageObserver, ListSelectionListener, MenuContainer, Scrollable, Serializable, TableColumnModelListener, TableModelListener

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.
See Also:
Serialized Form

Nested Class Summary

protected class
JTable.AccessibleJTable
Provides accessibility support for JTable.

Nested classes/interfaces inherited from class javax.swing.JComponent

JComponent.AccessibleJComponent

Nested classes/interfaces inherited from class java.awt.Container

Container.AccessibleAWTContainer

Nested classes/interfaces inherited from class java.awt.Component

Component.AccessibleAWTComponent, Component.BltBufferStrategy, Component.FlipBufferStrategy

Field Summary

static 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.
static 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.
static int
AUTO_RESIZE_NEXT_COLUMN
When resizing column i, automatically change only the single column i+1 to provide or absorb excess space requirements.
static int
AUTO_RESIZE_OFF
When resizing columns, do not automatically change any columns.
static 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.
protected boolean
autoCreateColumnsFromModel
Whether or not the table should automatically compute a matching TableColumnModel and assign it to the columnModel property when the dataModel property is changed.
protected int
autoResizeMode
A numeric code specifying the resizing behavior of the table.
protected TableCellEditor
cellEditor
The current cell editor.
protected boolean
cellSelectionEnabled
Obsolete.
protected TableColumnModel
columnModel
A model of various aspects of the columns of the table, not including the data stored in them.
protected TableModel
dataModel
The model for data stored in the table.
protected Hashtable<K,V>
defaultEditorsByColumnClass
A table mapping Class objects to TableCellEditor objects.
protected Hashtable<K,V>
defaultRenderersByColumnClass
A table mapping Class objects to TableCellEditor objects.
protected int
editingColumn
The column that is edited, -1 if the table is not edited currently.
protected int
editingRow
The row that is edited, -1 if the table is not edited currently.
protected Component
editorComp
The component that is used for editing.
protected Color
gridColor
The color to paint the grid lines of the table, when either showHorizontalLines or showVerticalLines is set.
protected Dimension
preferredViewportSize
The size this table would prefer its viewport assume, if it is contained in a JScrollPane.
protected int
rowHeight
The height in pixels of any row of the table.
protected int
rowMargin
The height in pixels of the gap left between any two rows of the table.
protected boolean
rowSelectionAllowed
Whether or not the table should allow row selection.
protected Color
selectionBackground
The color to paint the background of selected cells.
protected Color
selectionForeground
The color to paint the foreground of selected cells.
protected ListSelectionModel
selectionModel
A model of the rows of this table which are currently selected.
protected boolean
showHorizontalLines
The showHorizontalLines property.
protected boolean
showVerticalLines
The showVerticalLines property.
protected JTableHeader
tableHeader
The tableHeader property.

Fields inherited from class javax.swing.JComponent

TOOL_TIP_TEXT_KEY, UNDEFINED_CONDITION, WHEN_ANCESTOR_OF_FOCUSED_COMPONENT, WHEN_FOCUSED, WHEN_IN_FOCUSED_WINDOW, accessibleContext, listenerList, ui

Fields inherited from class java.awt.Component

BOTTOM_ALIGNMENT, CENTER_ALIGNMENT, LEFT_ALIGNMENT, RIGHT_ALIGNMENT, TOP_ALIGNMENT

Fields inherited from interface java.awt.image.ImageObserver

ABORT, ALLBITS, ERROR, FRAMEBITS, HEIGHT, PROPERTIES, SOMEBITS, WIDTH

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(Vector<T> data, Vector<T> columnNames)
Creates a new JTable instance that uses data and column names, stored in Vectors.
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.

Method Summary

void
addColumn(TableColumn column)
Add the new table column.
void
addColumnSelectionInterval(int index0, int index1)
void
addNotify()
Called when this container is added to another container to inform it to create its peer.
void
addRowSelectionInterval(int index0, int index1)
void
changeSelection(int rowIndex, int columnIndex, boolean toggle, boolean extend)
void
clearSelection()
void
columnAdded(TableColumnModelEvent event)
Invoked when the column is added.
int
columnAtPoint(Point point)
Returns index of the column that contains specified point or -1 if this table doesn't contain this point.
void
columnMarginChanged(ChangeEvent event)
Invoked when the column margin is changed.
void
columnMoved(TableColumnModelEvent event)
Invoked when the column is moved.
void
columnRemoved(TableColumnModelEvent event)
Invoked when the column is removed.
void
columnSelectionChanged(ListSelectionEvent event)
Invoked when the the column selection changes, repaints the changed columns.
protected void
configureEnclosingScrollPane()
int
convertColumnIndexToModel(int vc)
Convert the table model index into the table column number.
int
convertColumnIndexToView(int mc)
Convert the table column number to the table column model index.
protected TableColumnModel
createDefaultColumnModel()
Create the default table column model that is used if the user-defined column model is not provided.
void
createDefaultColumnsFromModel()
Clears any existing columns from the JTable's TableColumnModel and creates new columns to match the values in the data (TableModel) used by the table.
protected TableModel
createDefaultDataModel()
Create the default table data model that is used if the user-defined data model is not provided.
protected void
createDefaultEditors()
Create the default editors for this table.
protected void
createDefaultRenderers()
Create the default renderers for this table.
protected ListSelectionModel
createDefaultSelectionModel()
Create the default table selection model that is used if the user-defined selection model is not provided.
protected JTableHeader
createDefaultTableHeader()
Create the default table header, if the user - defined table header is not provided.
static JScrollPane
createScrollPaneForTable(JTable table)
Deprecated. 1.0.2, replaced by new JScrollPane(JTable)
void
doLayout()
Set the widths of all columns, taking they preferred widths into consideration.
boolean
editCellAt(int row, int column)
Programmatically starts editing the specified cell.
boolean
editCellAt(int row, int column, EventObject e)
Programmatically starts editing the specified cell.
void
editingCanceled(ChangeEvent event)
Invoked when the editing is cancelled.
void
editingStopped(ChangeEvent event)
Finish the current editing session and update the table with the new value by calling setValueAt(Object,int,int).
AccessibleContext
getAccessibleContext()
Get the value of the JComponent.accessibleContext property.
boolean
getAutoCreateColumnsFromModel()
Get the value of the autoCreateColumnsFromModel property.
int
getAutoResizeMode()
Get the value of the autoResizeMode property.
TableCellEditor
getCellEditor()
Get the value of the cellEditor property.
TableCellEditor
getCellEditor(int row, int column)
Get the cell editor, suitable for editing the given cell.
Rectangle
getCellRect(int row, int column, boolean includeSpacing)
Calculate the visible rectangle for a particular row and column.
TableCellRenderer
getCellRenderer(int row, int column)
Get the cell renderer for rendering the given cell.
boolean
getCellSelectionEnabled()
Get the value of the cellSelectionEnabled property.
TableColumn
getColumn(Object identifier)
Get table column with the given identified.
Class
getColumnClass(int column)
Get the class (datatype) of the column.
int
getColumnCount()
Get the value of the columnCount property by delegation to the columnModel field.
TableColumnModel
getColumnModel()
Get the value of the columnModel property.
String
getColumnName(int column)
Get the name of the column.
boolean
getColumnSelectionAllowed()
Get the value of the columnSelectionAllowed property.
TableCellEditor
getDefaultEditor(Class columnClass)
Get the default editor for editing values of the given type (String, Boolean and so on).
TableCellRenderer
getDefaultRenderer(Class columnClass)
Get the default renderer for rendering the given data type.
boolean
getDragEnabled()
Get the value of the dragEnabled property.
int
getEditingColumn()
Get the column, currently being edited
int
getEditingRow()
Get the row currently being edited.
Component
getEditorComponent()
Get the editor component that is currently editing one of the cells
Color
getGridColor()
Get the value of the gridColor property.
Dimension
getIntercellSpacing()
Get the value of the intercellSpacing property.
TableModel
getModel()
Get the value of the dataModel property.
Dimension
getPreferredScrollableViewportSize()
Get the value of the preferredViewportSize property.
int
getRowCount()
Get the value of the rowCount property by delegation to the dataModel field.
int
getRowHeight()
Get the value of the rowHeight property.
int
getRowHeight(int row)
Get the height of the specified row.
int
getRowMargin()
Get the value of the rowMargin property.
boolean
getRowSelectionAllowed()
Get the value of the rowSelectionAllowed property.
int
getScrollableBlockIncrement(Rectangle visibleRect, int orientation, int direction)
boolean
getScrollableTracksViewportHeight()
Get the value of the scrollableTracksViewportHeight property.
boolean
getScrollableTracksViewportWidth()
Get the value of the scrollableTracksViewportWidth property.
int
getScrollableUnitIncrement(Rectangle visibleRect, int orientation, int direction)
Return the preferred scrolling amount (in pixels) for the given scrolling direction and orientation.
int
getSelectedColumn()
Get the value of the selectedColumn property by delegation to the columnModel field.
int
getSelectedColumnCount()
Get the value of the selectedColumnCount property by delegation to the columnModel field.
int[]
getSelectedColumns()
Get the value of the selectedColumns property by delegation to the columnModel field.
int
getSelectedRow()
Get the value of the selectedRow property by delegation to the ListSelectionModel.getMinSelectionIndex() method of the selectionModel field.
int
getSelectedRowCount()
Get the value of the selectedRowCount property by delegation to the selectionModel field.
int[]
getSelectedRows()
Get the value of the selectedRows property by delegation to the selectionModel field.
Color
getSelectionBackground()
Get the value of the selectionBackground property.
Color
getSelectionForeground()
Get the value of the selectionForeground property.
ListSelectionModel
getSelectionModel()
Get the value of the selectionModel property.
boolean
getShowHorizontalLines()
Get the value of the showHorizontalLines property.
boolean
getShowVerticalLines()
Get the value of the showVerticalLines property.
boolean
getSurrendersFocusOnKeystroke()
Returns whether cell editors of this table should receive keyboard focus when the editor is activated by a keystroke.
JTableHeader
getTableHeader()
Get the value of the tableHeader property.
TableUI
getUI()
This method returns the table's UI delegate.
String
getUIClassID()
Object
getValueAt(int row, int column)
Get the cell value at the given position.
protected void
initializeLocalVars()
Initialize local variables to default values.
boolean
isCellEditable(int row, int column)
Returns true if the specified cell is editable, and false otherwise.
boolean
isCellSelected(int row, int column)
Checks if the given cell is selected.
boolean
isColumnSelected(int column)
Checks if the given column is selected.
boolean
isEditing()
Check if one of the table cells is currently being edited.
boolean
isRowSelected(int row)
Checks if the given row is selected.
void
moveColumn(int column, int targetColumn)
Moves column at the specified index to new given location.
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).
Component
prepareRenderer(TableCellRenderer renderer, int row, int column)
Prepare the renderer for rendering the given cell.
void
removeColumn(TableColumn column)
Removes specified column from displayable columns of this table.
void
removeColumnSelectionInterval(int index0, int index1)
void
removeEditor()
Discards the editor object.
void
removeNotify()
Called when this container is removed from its parent container to inform it to destroy its peer.
void
removeRowSelectionInterval(int index0, int index1)
protected void
resizeAndRepaint()
This revalidates the JTable and queues a repaint.
int
rowAtPoint(Point point)
Returns index of the row that contains specified point or -1 if this table doesn't contain this point.
void
selectAll()
Select all table.
void
setAutoCreateColumnsFromModel(boolean autoCreate)
Set the value of the autoCreateColumnsFromModel flag.
void
setAutoResizeMode(int a)
Set the value of the autoResizeMode property.
void
setCellEditor(TableCellEditor c)
Set the value of the cellEditor property.

Unregister this as a CellEditorListener from previous cellEditor and register it with new parameter c.

void
setCellSelectionEnabled(boolean c)
Set the value of the cellSelectionEnabled property.
void
setColumnModel(TableColumnModel c)
Set the value of the columnModel property.

Unregister this as a TableColumnModelListener from previous columnModel and register it with new parameter c.

void
setColumnSelectionAllowed(boolean c)
Set the value of the columnSelectionAllowed property.
void
setColumnSelectionInterval(int index0, int index1)
void
setDefaultEditor(Class columnClass, TableCellEditor editor)
Set the default editor for the given column class (column data type).
void
setDefaultRenderer(Class columnClass, TableCellRenderer rend)
Set default renderer for rendering the given data type.
void
setDragEnabled(boolean d)
Set the value of the dragEnabled property.
void
setEditingColumn(int column)
Set the column, currently being edited
void
setEditingRow(int row)
Set the row currently being edited.
void
setGridColor(Color g)
Set the value of the gridColor property.
void
setIntercellSpacing(Dimension i)
Set the value of the intercellSpacing property.
void
setModel(TableModel m)
Set the value of the dataModel property.

Unregister this as a TableModelListener from previous dataModel and register it with new parameter m.

void
setPreferredScrollableViewportSize(Dimension p)
Set the value of the preferredViewportSize property.
void
setRowHeight(int r)
Sets the height for all rows in the table.
void
setRowHeight(int row, int rh)
Sets the height of a single row in the table.
void
setRowMargin(int r)
Set the value of the rowMargin property.
void
setRowSelectionAllowed(boolean r)
Set the value of the rowSelectionAllowed property.
void
setRowSelectionInterval(int index0, int index1)
void
setSelectionBackground(Color s)
Set the value of the selectionBackground property.

Fire a PropertyChangeEvent with name SELECTION_BACKGROUND_CHANGED_PROPERTY to registered listeners, if selectionBackground changed.

void
setSelectionForeground(Color s)
Set the value of the selectionForeground property.

Fire a PropertyChangeEvent with name SELECTION_FOREGROUND_CHANGED_PROPERTY to registered listeners, if selectionForeground changed.

void
setSelectionMode(int s)
Set the value of the selectionMode property by delegation to the selectionModel field.
void
setSelectionModel(ListSelectionModel s)
Set the value of the selectionModel property.

Unregister this as a ListSelectionListener from previous selectionModel and register it with new parameter s.

void
setShowGrid(boolean s)
Set the value of the showGrid property.
void
setShowHorizontalLines(boolean s)
Set the value of the showHorizontalLines property.
void
setShowVerticalLines(boolean s)
Set the value of the showVerticalLines property.
void
setSurrendersFocusOnKeystroke(boolean value)
Sets whether cell editors of this table should receive keyboard focus when the editor is activated by a keystroke.
void
setTableHeader(JTableHeader t)
Set the value of the tableHeader property.
void
setUI(TableUI ui)
This method sets the table's UI delegate.
void
setValueAt(Object value, int row, int column)
Set value for the cell at the given position.
void
sizeColumnsToFit(boolean lastColumnOnly)
Deprecated. Replaced by doLayout()
void
sizeColumnsToFit(int resizingColumn)
Obsolete since JDK 1.4.
void
tableChanged(TableModelEvent event)
Invoked when the table changes.
protected void
unconfigureEnclosingScrollPane()
void
updateUI()
void
valueChanged(ListSelectionEvent event)
Invoked when another table row is selected.

Methods inherited from class javax.swing.JComponent

addAncestorListener, addNotify, addVetoableChangeListener, computeVisibleRect, contains, createToolTip, disable, enable, extends EventListener> T[] getListeners, firePropertyChange, firePropertyChange, fireVetoableChange, getAccessibleContext, getActionForKeyStroke, getActionMap, getAlignmentX, getAlignmentY, getAncestorListeners, getAutoscrolls, getBorder, getBounds, getClientProperty, getComponentGraphics, getComponentPopupMenu, getConditionForKeyStroke, getDebugGraphicsOptions, getDefaultLocale, getGraphics, getHeight, getInheritsPopupMenu, getInputMap, getInputMap, getInputVerifier, getInsets, getInsets, getLocation, getMaximumSize, getMinimumSize, getNextFocusableComponent, getPreferredSize, getRegisteredKeyStrokes, getRootPane, getSize, getToolTipLocation, getToolTipText, getToolTipText, getTopLevelAncestor, getTransferHandler, getUIClassID, getVerifyInputWhenFocusTarget, getVetoableChangeListeners, getVisibleRect, getWidth, getX, getY, grabFocus, isDoubleBuffered, isLightweightComponent, isManagingFocus, isOpaque, isOptimizedDrawingEnabled, isPaintingTile, isRequestFocusEnabled, isValidateRoot, paint, paintBorder, paintChildren, paintComponent, paintImmediately, paintImmediately, paramString, print, printAll, printBorder, printChildren, printComponent, processComponentKeyEvent, processKeyBinding, processKeyEvent, processMouseMotionEvent, putClientProperty, registerKeyboardAction, registerKeyboardAction, removeAncestorListener, removeNotify, removeVetoableChangeListener, repaint, repaint, requestDefaultFocus, requestFocus, requestFocus, requestFocusInWindow, requestFocusInWindow, resetKeyboardActions, reshape, revalidate, scrollRectToVisible, setActionMap, setAlignmentX, setAlignmentY, setAutoscrolls, setBackground, setBorder, setComponentPopupMenu, setDebugGraphicsOptions, setDefaultLocale, setDoubleBuffered, setEnabled, setFont, setForeground, setInheritsPopupMenu, setInputMap, setInputVerifier, setNextFocusableComponent, setOpaque, setRequestFocusEnabled, setToolTipText, setTransferHandler, setUI, setVerifyInputWhenFocusTarget, setVisible, unregisterKeyboardAction, update, updateUI

Methods inherited from class java.awt.Container

add, add, add, add, add, addContainerListener, addImpl, addNotify, addPropertyChangeListener, addPropertyChangeListener, applyComponentOrientation, areFocusTraversalKeysSet, countComponents, deliverEvent, doLayout, extends EventListener> T[] getListeners, findComponentAt, findComponentAt, getAlignmentX, getAlignmentY, getComponent, getComponentAt, getComponentAt, getComponentCount, getComponentZOrder, getComponents, getContainerListeners, getFocusTraversalKeys, getFocusTraversalPolicy, getInsets, getLayout, getMaximumSize, getMinimumSize, getMousePosition, getPreferredSize, insets, invalidate, isAncestorOf, isFocusCycleRoot, isFocusCycleRoot, isFocusTraversalPolicyProvider, isFocusTraversalPolicySet, layout, list, list, locate, minimumSize, paint, paintComponents, paramString, preferredSize, print, printComponents, processContainerEvent, processEvent, remove, remove, removeAll, removeContainerListener, removeNotify, setComponentZOrder, setFocusCycleRoot, setFocusTraversalKeys, setFocusTraversalPolicy, setFocusTraversalPolicyProvider, setFont, setLayout, transferFocusDownCycle, update, validate, validateTree

Methods inherited from class java.awt.Component

action, add, addComponentListener, addFocusListener, addHierarchyBoundsListener, addHierarchyListener, addInputMethodListener, addKeyListener, addMouseListener, addMouseMotionListener, addMouseWheelListener, addNotify, addPropertyChangeListener, addPropertyChangeListener, applyComponentOrientation, areFocusTraversalKeysSet, bounds, checkImage, checkImage, coalesceEvents, contains, contains, createImage, createImage, createVolatileImage, createVolatileImage, deliverEvent, disable, disableEvents, dispatchEvent, doLayout, enable, enable, enableEvents, enableInputMethods, extends EventListener> T[] getListeners, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, getAccessibleContext, getAlignmentX, getAlignmentY, getBackground, getBounds, getBounds, getColorModel, getComponentAt, getComponentAt, getComponentListeners, getComponentOrientation, getCursor, getDropTarget, getFocusCycleRootAncestor, getFocusListeners, getFocusTraversalKeys, getFocusTraversalKeysEnabled, getFont, getFontMetrics, getForeground, getGraphics, getGraphicsConfiguration, getHeight, getHierarchyBoundsListeners, getHierarchyListeners, getIgnoreRepaint, getInputContext, getInputMethodListeners, getInputMethodRequests, getKeyListeners, getLocale, getLocation, getLocation, getLocationOnScreen, getMaximumSize, getMinimumSize, getMouseListeners, getMouseMotionListeners, getMousePosition, getMouseWheelListeners, getName, getParent, getPeer, getPreferredSize, getPropertyChangeListeners, getPropertyChangeListeners, getSize, getSize, getToolkit, getTreeLock, getWidth, getX, getY, gotFocus, handleEvent, hasFocus, hide, imageUpdate, inside, invalidate, isBackgroundSet, isCursorSet, isDisplayable, isDoubleBuffered, isEnabled, isFocusCycleRoot, isFocusOwner, isFocusTraversable, isFocusable, isFontSet, isForegroundSet, isLightweight, isMaximumSizeSet, isMinimumSizeSet, isOpaque, isPreferredSizeSet, isShowing, isValid, isVisible, keyDown, keyUp, layout, list, list, list, list, list, locate, location, lostFocus, minimumSize, mouseDown, mouseDrag, mouseEnter, mouseExit, mouseMove, mouseUp, move, nextFocus, paint, paintAll, paramString, postEvent, preferredSize, prepareImage, prepareImage, print, printAll, processComponentEvent, processEvent, processFocusEvent, processHierarchyBoundsEvent, processHierarchyEvent, processInputMethodEvent, processKeyEvent, processMouseEvent, processMouseMotionEvent, processMouseWheelEvent, remove, removeComponentListener, removeFocusListener, removeHierarchyBoundsListener, removeHierarchyListener, removeInputMethodListener, removeKeyListener, removeMouseListener, removeMouseMotionListener, removeMouseWheelListener, removeNotify, removePropertyChangeListener, removePropertyChangeListener, repaint, repaint, repaint, repaint, requestFocus, requestFocus, requestFocusInWindow, requestFocusInWindow, reshape, resize, resize, setBackground, setBounds, setBounds, setComponentOrientation, setCursor, setDropTarget, setEnabled, setFocusTraversalKeys, setFocusTraversalKeysEnabled, setFocusable, setFont, setForeground, setIgnoreRepaint, setLocale, setLocation, setLocation, setMaximumSize, setMinimumSize, setName, setPreferredSize, setSize, setSize, setVisible, show, show, size, toString, transferFocus, transferFocusBackward, transferFocusUpCycle, update, validate

Methods inherited from class java.lang.Object

clone, equals, extends Object> getClass, finalize, hashCode, notify, notifyAll, toString, wait, wait, wait

Field Details

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.
Field Value:
4

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.
Field Value:
3

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.
Field Value:
1

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 JScrollPane in order to accomodate cases in which the table size exceeds its visible area.
Field Value:
0

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.
Field Value:
2

autoCreateColumnsFromModel

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

autoResizeMode

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

cellEditor

protected TableCellEditor cellEditor
The current cell editor.

cellSelectionEnabled

protected boolean cellSelectionEnabled

columnModel

protected TableColumnModel columnModel
A model of various aspects of the columns of the table, not including the data stored in them. The TableColumnModel is principally concerned with holding a set of 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 ListSelectionModel which indicates which columns are currently selected. This selection model works in combination with the 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 autoCreateColumnsFromModel will construct the columnModel automatically, and the table acts as a facade for most of the interesting properties of the columnModel anyways.


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 TableModelListener.

defaultEditorsByColumnClass

protected Hashtable<K,V> defaultEditorsByColumnClass
A table mapping Class objects to TableCellEditor objects. This table is consulted by the FIXME

defaultRenderersByColumnClass

protected Hashtable<K,V> defaultRenderersByColumnClass
A table mapping Class objects to 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 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 showHorizontalLines or showVerticalLines is set.

preferredViewportSize

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

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 columnModel.

rowMargin

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

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.

selectionBackground

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

selectionForeground

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

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 columnModel property, to represent the rows and columns (or both: cells) of the table which are currently selected.

showHorizontalLines

protected boolean showHorizontalLines
The showHorizontalLines property.

showVerticalLines

protected boolean showVerticalLines
The showVerticalLines property.

tableHeader

protected JTableHeader tableHeader
The tableHeader property.

Constructor Details

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 JScrollPane.
Parameters:
data - an Object[][] the table data
columnNames - an Object[] the column headers

JTable

public JTable(Vector<T> data,
              Vector<T> columnNames)
Creates a new JTable instance that uses data and column names, stored in Vectors.
Parameters:
data - the table data
columnNames - the table column names.

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)

Method Details

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()
Called when this container is added to another container to inform it to create its peer. Peers for any child components will also be created.
Overrides:
addNotify in interface JComponent

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.
Specified by:
columnAdded in interface TableColumnModelListener

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.
Specified by:
columnMarginChanged in interface TableColumnModelListener

columnMoved

public void columnMoved(TableColumnModelEvent event)
Invoked when the column is moved. Revalidates and repains the table.
Specified by:
columnMoved in interface TableColumnModelListener

columnRemoved

public void columnRemoved(TableColumnModelEvent event)
Invoked when the column is removed. Revalidates and repains the table.
Specified by:
columnRemoved in interface TableColumnModelListener

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.
Specified by:
columnSelectionChanged in interface TableColumnModelListener

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.

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

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 DefaultTableColumnModel.
Returns:
the created table column model.

createDefaultColumnsFromModel

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

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 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 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.
Overrides:
doLayout in interface Container

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.
Specified by:
editingCanceled in interface CellEditorListener

editingStopped

public void editingStopped(ChangeEvent event)
Finish the current editing session and update the table with the new value by calling setValueAt(Object,int,int).
Specified by:
editingStopped in interface CellEditorListener
Parameters:
event - the change event

getAccessibleContext

public AccessibleContext getAccessibleContext()
Get the value of the JComponent.accessibleContext property.
Specified by:
getAccessibleContext in interface Accessible
Overrides:
getAccessibleContext in interface JComponent
Returns:
The current value of the property

getAutoCreateColumnsFromModel

public boolean getAutoCreateColumnsFromModel()
Get the value of the autoCreateColumnsFromModel property.
Returns:
The current value of the property

getAutoResizeMode

public int getAutoResizeMode()
Get the value of the autoResizeMode property.
Returns:
The current value of the property

getCellEditor

public TableCellEditor getCellEditor()
Get the value of the cellEditor 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 getDefaultEditor(Class) with the parameter, obtained from TableModel.getColumnClass(int).
Parameters:
row - the cell row
column - the cell column
Returns:
the editor to edit that cell

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 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 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 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.

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 columnModel field.
Returns:
The current value of the columnCount property

getColumnModel

public TableColumnModel getColumnModel()
Get the value of the 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 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

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 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 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 dataModel property.
Returns:
The current value of the property

getPreferredScrollableViewportSize

public Dimension getPreferredScrollableViewportSize()
Get the value of the preferredViewportSize property.
Specified by:
getPreferredScrollableViewportSize in interface Scrollable
Returns:
The current value of the property

getRowCount

public int getRowCount()
Get the value of the rowCount property by delegation to the dataModel field.
Returns:
The current value of the rowCount property

getRowHeight

public int getRowHeight()
Get the value of the 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 rowMargin property.
Returns:
The current value of the property

getRowSelectionAllowed

public boolean getRowSelectionAllowed()
Get the value of the rowSelectionAllowed property.
Returns:
The current value of the property

getScrollableBlockIncrement

public int getScrollableBlockIncrement(Rectangle visibleRect,
                                       int orientation,
                                       int direction)
Specified by:
getScrollableBlockIncrement in interface Scrollable

getScrollableTracksViewportHeight

public boolean getScrollableTracksViewportHeight()
Get the value of the scrollableTracksViewportHeight property.
Specified by:
getScrollableTracksViewportHeight in interface Scrollable
Returns:
The constant value false

getScrollableTracksViewportWidth

public boolean getScrollableTracksViewportWidth()
Get the value of the scrollableTracksViewportWidth property.
Specified by:
getScrollableTracksViewportWidth in interface Scrollable
Returns:
true unless the 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.
Specified by:
getScrollableUnitIncrement in interface Scrollable
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 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 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 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 ListSelectionModel.getMinSelectionIndex() method of the 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 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 selectionModel field.
Returns:
The current value of the selectedRows property

getSelectionBackground

public Color getSelectionBackground()
Get the value of the selectionBackground property.
Returns:
The current value of the property

getSelectionForeground

public Color getSelectionForeground()
Get the value of the selectionForeground property.
Returns:
The current value of the property

getSelectionModel

public ListSelectionModel getSelectionModel()
Get the value of the selectionModel property.
Returns:
The current value of the property

getShowHorizontalLines

public boolean getShowHorizontalLines()
Get the value of the showHorizontalLines property.
Returns:
The current value of the property

getShowVerticalLines

public boolean getShowVerticalLines()
Get the value of the 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 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()
Overrides:
getUIClassID in interface JComponent

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()
Called when this container is removed from its parent container to inform it to destroy its peer. This causes the peers of all child component to be destroyed as well.
Overrides:
removeNotify in interface JComponent

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 autoCreateColumnsFromModel flag. If the flag changes from false to true, the createDefaultColumnsFromModel() method is called.
Parameters:
autoCreate - the new value of the flag.

setAutoResizeMode

public void setAutoResizeMode(int a)
Set the value of the autoResizeMode property.
Parameters:
a - The new value of the autoResizeMode property

setCellEditor

public void setCellEditor(TableCellEditor c)
Set the value of the cellEditor property.

Unregister this as a CellEditorListener from previous 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 cellSelectionEnabled property.
Parameters:
c - The new value of the cellSelectionEnabled property

setColumnModel

public void setColumnModel(TableColumnModel c)
Set the value of the columnModel property.

Unregister this as a TableColumnModelListener from previous 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

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

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 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 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 dataModel property.

Unregister this as a TableModelListener from previous 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 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 setRowHeight(int,int).
Parameters:
r - the height to set for all rows

setRowHeight

public void setRowHeight(int row,
                         int rh)
Sets the height of a single row in the table.
Parameters:
row - the row to change the height of
rh - the new row height

setRowMargin

public void setRowMargin(int r)
Set the value of the rowMargin property.
Parameters:
r - The new value of the rowMargin property

setRowSelectionAllowed

public void setRowSelectionAllowed(boolean r)
Set the value of the rowSelectionAllowed property.
Parameters:
r - The new value of the rowSelectionAllowed property

setRowSelectionInterval

public void setRowSelectionInterval(int index0,
                                    int index1)

setSelectionBackground

public void setSelectionBackground(Color s)
Set the value of the selectionBackground property.

Fire a PropertyChangeEvent with name 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 selectionForeground property.

Fire a PropertyChangeEvent with name 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 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 selectionModel property.

Unregister this as a ListSelectionListener from previous 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 showHorizontalLines property.
Parameters:
s - The new value of the showHorizontalLines property

setShowVerticalLines

public void setShowVerticalLines(boolean s)
Set the value of the 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 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.
Specified by:
tableChanged in interface TableModelListener

unconfigureEnclosingScrollPane

protected void unconfigureEnclosingScrollPane()

updateUI

public void updateUI()
Overrides:
updateUI in interface JComponent

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.
Specified by:
valueChanged in interface ListSelectionListener

JTable.java -- Copyright (C) 2002, 2004, 2005, 2006 Free Software Foundation, Inc. This file is part of GNU Classpath. GNU Classpath is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2, or (at your option) any later version. GNU Classpath is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with GNU Classpath; see the file COPYING. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. Linking this library statically or dynamically with other modules is making a combined work based on this library. Thus, the terms and conditions of the GNU General Public License cover the whole combination. As a special exception, the copyright holders of this library give you permission to link this library with independent modules to produce an executable, regardless of the license terms of these independent modules, and to copy and distribute the resulting executable under terms of your choice, provided that you also meet, for each linked independent module, the terms and conditions of the license of that module. An independent module is a module which is not derived from or based on this library. If you modify this library, you may extend this exception to your version of the library, but you are not obligated to do so. If you do not wish to do so, delete this exception statement from your version.