javax.swing
Class JTable

java.lang.Object
  extended by java.awt.Component
      extended by java.awt.Container
          extended by javax.swing.JComponent
              extended by javax.swing.JTable
All Implemented Interfaces:
ImageObserver, MenuContainer, Serializable, EventListener, Accessible, CellEditorListener, ListSelectionListener, TableColumnModelListener, TableModelListener, Scrollable

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 defaultEditorsByColumnClass
          A table mapping Class objects to TableCellEditor objects.
protected  Hashtable 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
accessibleContext, listenerList, TOOL_TIP_TEXT_KEY, ui, UNDEFINED_CONDITION, WHEN_ANCESTOR_OF_FOCUSED_COMPONENT, WHEN_FOCUSED, WHEN_IN_FOCUSED_WINDOW
 
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(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 Vectors.
 
Method Summary
 void addColumn(TableColumn column)
          Add the new table column.
 void addColumnSelectionInterval(int index0, int index1)
           
 void addNotify()
          Receives notification if this component is added to a parent component.
 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(java.lang.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)
          Return the preferred scrolling amount (in pixels) for the given scrolling direction and orientation when scrolling in large amounts (pages).
 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()
          Get the value of the UIClassID property.
 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()
          Receives notification that this component no longer has a parent.
 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.
 void setCellSelectionEnabled(boolean c)
          Set the value of the cellSelectionEnabled property.
 void setColumnModel(TableColumnModel c)
          Set the value of the columnModel property.
 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.
 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.
 void setSelectionForeground(Color s)
          Set the value of the selectionForeground property.
 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.
 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()
          This method should be overridden in subclasses.
 void valueChanged(ListSelectionEvent event)
          Invoked when another table row is selected.
 
Methods inherited from class javax.swing.JComponent
addAncestorListener, addVetoableChangeListener, computeVisibleRect, contains, createToolTip, disable, enable, firePropertyChange, firePropertyChange, fireVetoableChange, getActionForKeyStroke, getActionMap, getAlignmentX, getAlignmentY, getAncestorListeners, getAutoscrolls, getBorder, getBounds, getClientProperty, getComponentGraphics, getComponentPopupMenu, getConditionForKeyStroke, getDebugGraphicsOptions, getDefaultLocale, getGraphics, getHeight, getInheritsPopupMenu, getInputMap, getInputMap, getInputVerifier, getInsets, getInsets, getListeners, getLocation, getMaximumSize, getMinimumSize, getNextFocusableComponent, getPreferredSize, getRegisteredKeyStrokes, getRootPane, getSize, getToolTipLocation, getToolTipText, getToolTipText, getTopLevelAncestor, getTransferHandler, 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, 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
 
Methods inherited from class java.awt.Container
add, add, add, add, add, addContainerListener, addImpl, addPropertyChangeListener, addPropertyChangeListener, applyComponentOrientation, areFocusTraversalKeysSet, countComponents, deliverEvent, findComponentAt, findComponentAt, getComponent, getComponentAt, getComponentAt, getComponentCount, getComponents, getComponentZOrder, getContainerListeners, getFocusTraversalKeys, getFocusTraversalPolicy, getLayout, getMousePosition, insets, invalidate, isAncestorOf, isFocusCycleRoot, isFocusCycleRoot, isFocusTraversalPolicyProvider, isFocusTraversalPolicySet, layout, list, list, locate, minimumSize, paintComponents, preferredSize, printComponents, processContainerEvent, processEvent, remove, remove, removeAll, removeContainerListener, setComponentZOrder, setFocusCycleRoot, setFocusTraversalKeys, setFocusTraversalPolicy, setFocusTraversalPolicyProvider, setLayout, transferFocusDownCycle, validate, validateTree
 
Methods inherited from class java.awt.Component
action, add, addComponentListener, addFocusListener, addHierarchyBoundsListener, addHierarchyListener, addInputMethodListener, addKeyListener, addMouseListener, addMouseMotionListener, addMouseWheelListener, bounds, checkImage, checkImage, coalesceEvents, contains, createImage, createImage, createVolatileImage, createVolatileImage, disableEvents, dispatchEvent, enable, enableEvents, enableInputMethods, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, getBackground, getBounds, getColorModel, getComponentListeners, getComponentOrientation, getCursor, getDropTarget, getFocusCycleRootAncestor, getFocusListeners, getFocusTraversalKeysEnabled, getFont, getFontMetrics, getForeground, getGraphicsConfiguration, getHierarchyBoundsListeners, getHierarchyListeners, getIgnoreRepaint, getInputContext, getInputMethodListeners, getInputMethodRequests, getKeyListeners, getLocale, getLocation, getLocationOnScreen, getMouseListeners, getMouseMotionListeners, getMousePosition, getMouseWheelListeners, getName, getParent, getPeer, getPropertyChangeListeners, getPropertyChangeListeners, getSize, getToolkit, getTreeLock, gotFocus, handleEvent, hasFocus, hide, imageUpdate, inside, isBackgroundSet, isCursorSet, isDisplayable, isEnabled, isFocusable, isFocusOwner, isFocusTraversable, isFontSet, isForegroundSet, isLightweight, isMaximumSizeSet, isMinimumSizeSet, isPreferredSizeSet, isShowing, isValid, isVisible, keyDown, keyUp, list, list, list, location, lostFocus, mouseDown, mouseDrag, mouseEnter, mouseExit, mouseMove, mouseUp, move, nextFocus, paintAll, postEvent, prepareImage, prepareImage, processComponentEvent, processFocusEvent, processHierarchyBoundsEvent, processHierarchyEvent, processInputMethodEvent, processMouseEvent, processMouseWheelEvent, remove, removeComponentListener, removeFocusListener, removeHierarchyBoundsListener, removeHierarchyListener, removeInputMethodListener, removeKeyListener, removeMouseListener, removeMouseMotionListener, removeMouseWheelListener, removePropertyChangeListener, removePropertyChangeListener, repaint, repaint, repaint, resize, resize, setBounds, setBounds, setComponentOrientation, setCursor, setDropTarget, setFocusable, setFocusTraversalKeysEnabled, setIgnoreRepaint, setLocale, setLocation, setLocation, setMaximumSize, setMinimumSize, setName, setPreferredSize, setSize, setSize, show, show, size, toString, transferFocus, transferFocusBackward, transferFocusUpCycle
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

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.

See Also:
Constant Field Values

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.

See Also:
Constant Field Values

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.

See Also:
Constant Field Values

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.

See Also:
Constant Field Values

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.

See Also:
Constant Field Values

defaultEditorsByColumnClass

protected Hashtable defaultEditorsByColumnClass
A table mapping Class objects to TableCellEditor objects. This table is consulted by the FIXME


defaultRenderersByColumnClass

protected Hashtable 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 transient Component editorComp
The component that is used for editing. null if the table is not editing currently.


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.

See Also:
setModel(TableModel), createDefaultColumnsFromModel(), setColumnModel(TableColumnModel), setAutoCreateColumnsFromModel(boolean), getAutoCreateColumnsFromModel()

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.

See Also:
doLayout(), setAutoResizeMode(int), getAutoResizeMode()

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.

See Also:
getRowHeight(), setRowHeight(int), TableColumn.getWidth(), TableColumn.setWidth(int)

rowMargin

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

See Also:
setRowMargin(int), getRowHeight(), getIntercellSpacing(), setIntercellSpacing(Dimension), TableColumnModel.getColumnMargin(), TableColumnModel.setColumnMargin(int)

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:
TableColumnModel.getColumnSelectionAllowed(), setRowSelectionAllowed(boolean), getRowSelectionAllowed(), getCellSelectionEnabled(), setCellSelectionEnabled(boolean)

cellSelectionEnabled

protected boolean cellSelectionEnabled
Obsolete. Use rowSelectionAllowed, getColumnSelectionAllowed(), or the combined methods getCellSelectionEnabled() and setCellSelectionEnabled(boolean).


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.

See Also:
tableChanged(TableModelEvent), TableModel.addTableModelListener(TableModelListener)

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.

See Also:
setColumnModel(TableColumnModel), getColumnModel()

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.

See Also:
rowSelectionAllowed, setSelectionModel(ListSelectionModel), getSelectionModel(), TableColumnModel.getSelectionModel(), ListSelectionModel.addListSelectionListener(ListSelectionListener)

cellEditor

protected TableCellEditor cellEditor
The current cell editor.


gridColor

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

See Also:
setGridColor(Color), getGridColor()

preferredViewportSize

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

See Also:
setPreferredScrollableViewportSize(Dimension), getPreferredScrollableViewportSize()

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.

See Also:
setSelectionBackground(Color), getSelectionBackground()

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.

See Also:
setSelectionForeground(Color), getSelectionForeground()

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

Parameters:
data - the table data
columnNames - the table column names.
Method Detail

initializeLocalVars

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


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.

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.


createScrollPaneForTable

public static JScrollPane createScrollPaneForTable(JTable table)
Deprecated. 1.0.2, replaced by new JScrollPane(JTable)


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.

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.

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.

columnAdded

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

Specified by:
columnAdded in interface TableColumnModelListener
Parameters:
event - information about the column addition.

columnMarginChanged

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

Specified by:
columnMarginChanged in interface TableColumnModelListener
Parameters:
event - the event (identifies the source).

columnMoved

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

Specified by:
columnMoved in interface TableColumnModelListener
Parameters:
event - information about the column move.

columnRemoved

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

Specified by:
columnRemoved in interface TableColumnModelListener
Parameters:
event - information about the column removal.

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
Parameters:
event - information about the column selection state.

editingCanceled

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

Specified by:
editingCanceled in interface CellEditorListener
Parameters:
event - Change Event

editingStopped

public void editingStopped(ChangeEvent event)
Finish the current editing session and update the table with the new value by calling setValueAt(java.lang.Object, int, int).

Specified by:
editingStopped in interface CellEditorListener
Parameters:
event - the change event

tableChanged

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

Specified by:
tableChanged in interface TableModelListener
Parameters:
event - contains details of the update.

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
Parameters:
event - the event.

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.

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.

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

clearSelection

public void clearSelection()

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

getSelectionModel

public ListSelectionModel getSelectionModel()
Get the value of the selectionModel property.

Returns:
The current value of the property

getScrollableBlockIncrement

public int getScrollableBlockIncrement(Rectangle visibleRect,
                                       int orientation,
                                       int direction)
Description copied from interface: Scrollable
Return the preferred scrolling amount (in pixels) for the given scrolling direction and orientation when scrolling in large amounts (pages).

Specified by:
getScrollableBlockIncrement 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.
Returns:
the preferred scrolling distance, negative if up or left.

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.
Returns:
the preferred scrolling distance, negative if up or left.

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

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

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.

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

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.

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:
TableColumn.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:
TableColumn.getModelIndex()

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.

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

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
See Also:
setRowSelectionAllowed(boolean)

getCellSelectionEnabled

public boolean getCellSelectionEnabled()
Get the value of the cellSelectionEnabled 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

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

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

getColumnModel

public TableColumnModel getColumnModel()
Get the value of the columnModel property.

Returns:
The current value of the property

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

getColumnSelectionAllowed

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

Returns:
The current value of the columnSelectionAllowed property
See Also:
setColumnSelectionAllowed(boolean)

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

getAccessibleContext

public AccessibleContext getAccessibleContext()
Get the value of the JComponent.accessibleContext property.

Specified by:
getAccessibleContext in interface Accessible
Overrides:
getAccessibleContext in class JComponent
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

getDragEnabled

public boolean getDragEnabled()
Get the value of the dragEnabled property.

Returns:
The current value of the property

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

getPreferredScrollableViewportSize

public Dimension getPreferredScrollableViewportSize()
Get the value of the preferredViewportSize property.

Specified by:
getPreferredScrollableViewportSize in interface Scrollable
Returns:
The current value of the 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

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

getTableHeader

public JTableHeader getTableHeader()
Get the value of the tableHeader property.

Returns:
The current value of the property

removeColumn

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

Parameters:
column - column to removed

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

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

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
See Also:
getRowHeight(), setRowHeight(int, int), getRowHeight(int)

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 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
See Also:
getRowSelectionAllowed()

setCellSelectionEnabled

public void setCellSelectionEnabled(boolean c)
Set the value of the cellSelectionEnabled property.

Parameters:
c - The new value of the cellSelectionEnabled 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

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
See Also:
getColumnSelectionAllowed()

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

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

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

setDragEnabled

public void setDragEnabled(boolean d)
Set the value of the dragEnabled property.

Parameters:
d - The new value of the dragEnabled property

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

setPreferredScrollableViewportSize

public void setPreferredScrollableViewportSize(Dimension p)
Set the value of the preferredViewportSize property.

Parameters:
p - The new value of the preferredViewportSize property

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

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

setTableHeader

public void setTableHeader(JTableHeader t)
Set the value of the tableHeader property.

Parameters:
t - The new value of the tableHeader property

configureEnclosingScrollPane

protected void configureEnclosingScrollPane()

unconfigureEnclosingScrollPane

protected void unconfigureEnclosingScrollPane()

addNotify

public void addNotify()
Description copied from class: JComponent
Receives notification if this component is added to a parent component. Notification is sent to all registered AncestorListeners about the new parent. This method sets up ActionListeners for all registered KeyStrokes of this component in the chain of parent components. A PropertyChange event is fired to indicate that the ancestor property has changed. This method is used internally and should not be used in applications.

Overrides:
addNotify in class JComponent
See Also:
Component.isDisplayable(), Component.removeNotify()

removeNotify

public void removeNotify()
Description copied from class: JComponent
Receives notification that this component no longer has a parent. This method sends an AncestorEvent to all registered AncestorListeners, notifying them that the parent is gone. The keybord actions of this component are removed from the parent and its ancestors. A PropertyChangeEvent is fired to indicate that the 'ancestor' property has changed. This method is called before the component is actually removed from its parent, so the parent is still visible through Component.getParent().

Overrides:
removeNotify in class JComponent
See Also:
Component.isDisplayable(), Component.addNotify()

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 class Container
See Also:
TableColumn.setPreferredWidth(int)

sizeColumnsToFit

public void sizeColumnsToFit(boolean lastColumnOnly)
Deprecated. Replaced by doLayout()


sizeColumnsToFit

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


getUIClassID

public String getUIClassID()
Description copied from class: JComponent
Get the value of the UIClassID property. This property should be a key in the UIDefaults table managed by UIManager, the value of which is the name of a class to load for the component's JComponent.ui property.

Overrides:
getUIClassID in class JComponent
Returns:
A "symbolic" name which will map to a class to use for the component's UI, such as "ComponentUI"
See Also:
JComponent.setUI(javax.swing.plaf.ComponentUI), JComponent.updateUI()

getUI

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

Returns:
The table's UI delegate.

setUI

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

Parameters:
ui - The table's UI delegate.

updateUI

public void updateUI()
Description copied from class: JComponent
This method should be overridden in subclasses. In JComponent, the method does nothing. In subclasses, it should a UI delegate (corresponding to the symbolic name returned from JComponent.getUIClassID()) from the UIManager, and calls JComponent.setUI(javax.swing.plaf.ComponentUI) with the new delegate.

Overrides:
updateUI in class JComponent

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

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.

getEditingColumn

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

Returns:
the column, currently being edited.

setEditingColumn

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

Parameters:
column - the column, currently being edited.

getEditingRow

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

Returns:
the row, currently being edited.

setEditingRow

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

Parameters:
row - the row, that will be 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.

isEditing

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

Returns:
true if there is a cell being edited.

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.getColumnClass(int)

addColumnSelectionInterval

public void addColumnSelectionInterval(int index0,
                                       int index1)

addRowSelectionInterval

public void addRowSelectionInterval(int index0,
                                    int index1)

setColumnSelectionInterval

public void setColumnSelectionInterval(int index0,
                                       int index1)

setRowSelectionInterval

public void setRowSelectionInterval(int index0,
                                    int index1)

removeColumnSelectionInterval

public void removeColumnSelectionInterval(int index0,
                                          int index1)

removeRowSelectionInterval

public void removeRowSelectionInterval(int index0,
                                       int index1)

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.

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.

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

selectAll

public void selectAll()
Select all table.


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.

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

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:
TableColumn.setIdentifier(Object)

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.

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.

See Also:
setAutoCreateColumnsFromModel(boolean)

changeSelection

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

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.

removeEditor

public void removeEditor()
Discards the editor object.


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

resizeAndRepaint

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


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

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