All Packages  Class Hierarchy  This Package  Previous  Next  Index

Class com.sun.java.swing.JTable

java.lang.Object
   |
   +----java.awt.Component
           |
           +----java.awt.Container
                   |
                   +----com.sun.java.swing.JComponent
                           |
                           +----com.sun.java.swing.JTable

public class JTable
extends JComponent
implements TableModelListener, Scrollable, TableColumnModelListener, ListSelectionListener, CellEditorListener
JTable is a user-interface component that presents data in a two-dimensional table format. JTable's API is designed to be very easy to use for majority of the cases. But it is also designed to be very flexible for the expert users who would like to control all aspects of the table's configuration and behavior.

The most simple tables can be set up with a few quick lines of code. For example to set up an empty table with 4 columns and 10 rows:

JTable table = new JTable(); table.setAutoCreateColumnsFromModel(false); table.addColumn("First Name", 100, null, new DefaultCellEditor(new JTextField(""))); table.addColumn("Last Name", 100, null, new DefaultCellEditor(new JTextField(""))); table.addColumn("Vegetarian", 140, new DefaultCellRenderer(new JCheckBox()), new DefaultCellEditor(new JCheckBox())); table.addColumn("Birthday", 120); table.setNumRows(10);

Note: JSimpleTable assumes its model is a DefaultTableModel. If the model of the JSimpleTable is changed to another model class, most of the methods here will do nothing.


Variable Index

 o AUTO_RESIZE_ALL_COLUMNS
Proportionately resize all columns when table is resized
 o AUTO_RESIZE_LAST_COLUMN
Auto resize last column only when table is resized
 o AUTO_RESIZE_OFF
Do not auto resize column when table is resized.
 o autoCreateColumnsFromModel
The table will query the TableModel to build the default set of columns if this is true.
 o autoResizeMode
This mode value determines if table automatically resizes the width the table's columns to take up the entire width of the table, and how it does the resizing.
 o cellEditor
 o columnModel
The TableColumnModel of the table
 o dataModel
The TableModel of the table
 o editingColumn
 o editingRow
 o editorComp
If editing, Component that is handling the editing.
 o emptySelectionAllowed
Empty selection allowed in this table
 o gridColor
The color of the grid
 o isRowSelected
 o multipleSelectionAllowed
Multiple rows selected allowed in this table
 o preferredViewportSize
Used by the Scrollable interface to determine the initial visible area
 o rowHeight
The height of all rows in the table
 o rowMargin
The height margin between rows
 o rowSelectionAllowed
Row selection allowed in this table
 o selectionModel
The ListSelectionModel of the table, used to keep track of row selections
 o showGrid
The table draws a grid between cells if showGrid is true
 o simultaneousRowColumnSelectionAllowed
If this is true, then both a row selection and a column selection can be non-empty at the same time.
 o tableHeader
The TableHeader working with the table

Constructor Index

 o JTable()
Constructs a default JTable which is initialized with a default data model, a default column model, and a default selection model.
 o JTable(int, int)
Constructs a JTable with numColumns and numRows of empty cells using the DefaultTableModel.
 o JTable(Object[][], Object[])
Constructs a JTable using a DefaultTableModel and initialize the table with the values in the data array.
 o JTable(TableModel)
Constructs a JTable which is initialized with dm as the data model, a default column model, and a default selection model.
 o JTable(TableModel, TableColumnModel)
Constructs a JTable which is initialized with dm as the data model, cm as the column model, and a default selection model.
 o JTable(TableModel, TableColumnModel, ListSelectionModel)
Constructs a JTable which is initialized with dm as the data model, cm as the column model, and sm as the selection model.
 o JTable(Vector, Vector)
Constructs a JTable using a DefaultTableModel and initialize the table with the values in the data Vector.

Method Index

 o addColumn(Object, int)
 o addColumn(Object, int, TableCellRenderer, TableCellEditor)
 o addColumn(Object, int, TableCellRenderer, TableCellEditor, Vector)
Creates a new column with columnIdentifier, width, renderer, and editor to the end of the JTable's array of columns.
 o addColumn(Object, Vector)
Add a column to the table.
 o addColumn(TableColumn)
Appends aColumn to the end of the JTable's array of columns.
 o addColumnSelectionInterval(int, int)
Adds the columns from index0 to index0 inclusive to the current selection, if column selection and multiple selection is allowed.
 o addRow(Object[])
Add a row to the table.
 o addRow(Vector)
Add a row to the table.
 o addRowSelectionInterval(int, int)
Adds the rows from index0 to index0 inclusive to the current selection, if row selection and multiple selection is allowed.
 o checkDefaultTableModel()
Checks the table model.
 o clearSelection()
Deselects all selected columns and rows.
 o columnAdded(TableColumnModelEvent)
 o columnAtPoint(Point)
Returns the index of the column that point lies in, or -1 if it lies outside the receiver's bounds.
 o columnMarginChanged(ChangeEvent)
 o columnMoved(TableColumnModelEvent)
 o columnRemoved(TableColumnModelEvent)
 o columnSelectionChanged(ListSelectionEvent)
 o createDefaultColumnModel()
Returns the default column model object which is a DefaultTableColumnModel.
 o createDefaultColumnsFromModel()
This method will create default columns for the table from the data model using the getColumnCount(), getColumnIdentifier(), and getColumnType() methods defined in the TableModel interface.
 o createDefaultDataModel()
Returns the default table model object which is a DefaultTableModel.
 o createDefaultSelectionModel()
Returns the default selection model object which is a DefaultListSelectionModel.
 o createDefaultTableHeader()
Returns the default table header object which is a JTableHeader.
 o createScrollPaneForTable(JTable)
This static method is provided to simplify the task of wrapping a JTable in a scroll pane.
 o editColumnRow(int, int)
Programmatically starts editing the cell at column and row, if the cell is editable.
 o editColumnRow(int, int, EventObject)
Programmatically starts editing the cell at column and row, if the cell is editable.
 o editColumnRow(Object, int)
Programmatically starts editing the cell at column with identifier and row, if the cell is editable.
 o editingCanceled(ChangeEvent)
 o editingColumn()
If sent while isEditing() is true, this returns the index of the editing column; otherwise returns -1.
 o editingRow()
If sent while isEditing() is true, this returns the index of the editing row; otherwise returns -1.
 o editingStopped(ChangeEvent)
 o getAutoCreateColumnsFromModel()
Returns whether the table will create default columns from the model.
 o getAutoResizeMode()
Returns auto resize mode of the table.
 o getCellEditor()
Set the cellEditor variable
 o getCellRect(int, int, boolean)
Returns a rectangle locating the cell that lies at the intersection of column and row.
 o getColumn(Object)
Returns the TableColumn object for the column in the table whose identifier is equal to identifier, when compared using equals().
 o getColumnCount()
Returns the number of columns in the table
 o getColumnModel()
Returns the TableColumnModel that contains all column inforamtion of this table.
 o getColumnSelectionAllowed()
 o getEditorComponent()
If the receiver is currently editing this will return the Component that was returned from the CellEditor.
 o getEmptySelectionAllowed()
 o getGridColor()
Returns the color used to draw grid lines.
 o getIntercellSpacing()
Returns the horizontal and vertical spacing between cells.
 o getModel()
Returns the TableModel that provides the data displayed by the receiver.
 o getMultipleSelectionAllowed()
 o getPreferredScrollableViewportSize()
 o getPreferredScrollableViewportSize(Dimension)
 o getRowCount()
Returns the number of rows in the table.
 o getRowHeight()
Returns the height of a table row in the receiver.
 o getRowSelectionAllowed()
 o getScrollableBlockIncrement(Rectangle, int, int)
 o getScrollableTracksViewportHeight()
 o getScrollableTracksViewportWidth()
 o getScrollableUnitIncrement(Rectangle, int, int)
 o getSelectedColumn()
 o getSelectedColumnCount()
 o getSelectedColumns()
 o getSelectedRow()
 o getSelectedRowCount()
 o getSelectedRows()
 o getSelectionModel()
Returns the ListSelectionModel that is used to maintain row selection state.
 o getShowGrid()
Returns true if the receiver draws grid lines around cells, false if it doesn't.
 o getSimultaneousRowColumnSelectionAllowed()
 o getTableHeader()
Returns the tableHeader working with this JTable.
 o getToolTipText(MouseEvent)
Overriding to allow renderer's tips to be used if it has text set.
 o getUI()
 o getUIClassID()
 o getValueAt(int, int)
Returns the cell value at columnIndex and rowIndex.
 o getValueAt(Object, int)
Returns the cell value at columnIdentifier and rowIndex.
 o initializeLocalVars()
 o insertRow(int, Object[])
Insert a row at rowIndex in the table.
 o insertRow(int, Vector)
Insert a row at rowIndex in the table.
 o isCellEditable(int, int)
Returns true if the cell at columnIndex and rowIndex is editable.
 o isCellEditable(Object, int)
Returns true if the cell at columnIdentifier and rowIndex is editable.
 o isColumnSelected(int)
 o isColumnSelected(Object)
 o isEditing()
 o isOpaque()
Returns true if this component is completely opaque.
 o isRowSelected(int)
 o moveColumn(Object, Object)
Moves the column and heading at with the unique id columnIdentifier to the position currently occupied by the column with the unique id targetColumnIdentifier.
 o moveRow(int, int, int)
Moves one or more rows starting at startIndex to endIndex in the model to the toIndex.
 o prepareEditor(TableCellEditor, TableColumn, int)
 o removeColumn(Object)
Remove the column with an identifier that matches the parameter columnIdentifier.
 o removeColumn(TableColumn)
Removes aColumn from the JTable's array of columns.
 o removeColumnSelectionInterval(int, int)
Deselects the columns from index0 to index0 inclusive.
 o removeEditor()
 o removeRow(int)
Remove the row at rowIndex from the table.
 o removeRowSelectionInterval(int, int)
Deselects the rows from index0 to index0 inclusive.
 o resizeAndRepaint()
Properly sizes the receiver and its header view, and marks it as needing display.
 o resizeAndRepaint(int, int, int, int)
Properly sizes the receiver and its header view, and marks it as needing display.
 o rowAtPoint(Point)
Returns the index of the row that point lies in, or -1 if it lies outside the receiver's bounds.
 o selectAll()
If a column is selected, then this selects all columns.
 o setAutoCreateColumnsFromModel(boolean)
Sets the table's autoCreateColumnsFromModel flag.
 o setAutoResizeMode(int)
Sets the table's auto resize mode when the table is resized.
 o setBounds(int, int, int, int)
Overriding setBounds() to call sizeColumnsToFit() depending on the setting of autoResizeMode
 o setCellEditor(TableCellEditor)
Set the cellEditor variable
 o setColumnModel(TableColumnModel)
Sets the column model for this table to newModel and registers with for listner notifications from the new column model.
 o setColumnSelectionAllowed(boolean)
Sets whether the columns in this model can be selected.
 o setColumnSelectionInterval(int, int)
Selects the columns from index0 to index1 inclusive, if column selection is allowed.
 o setDataVector(Object[][], Object[])
 o setDataVector(Vector, Vector)
 o setEditingColumn(int)
Set the editingColumn variable
 o setEditingRow(int)
Set the editingRow variable
 o setEmptySelectionAllowed(boolean)
Sets whether the user can select zero columns or rows.
 o setGridColor(Color)
Sets the color used to draw grid lines to color and redisplays the receiver.
 o setIntercellSpacing(Dimension)
Sets the width and height between cells to newSpacing and redisplays the receiver.
 o setModel(TableModel)
Sets the data model for this table to newModel and registers with for listner notifications from the new data model.
 o setMultipleSelectionAllowed(boolean)
Sets whether the user can select more than one column or row at a time.
 o setNumRows(int)
Sets the number of rows in the table.
 o setRowHeight(int)
Sets the height for rows to newRowHeight and invokes tile
 o setRowSelectionAllowed(boolean)
Sets whether the rows in this model can be selected.
 o setRowSelectionInterval(int, int)
Selects the rows from index0 to index1 inclusive, if row selection is allowed.
 o setSelectionModel(ListSelectionModel)
Sets the row selection model for this table to newModel and registers with for listner notifications from the new selection model.
 o setShowGrid(boolean)
Sets whether the receiver draws grid lines around cells.
 o setSimultaneousRowColumnSelectionAllowed(boolean)
Sets whether this table allows both a column selection and a row selection to exist at the same time.
 o setTableHeader(JTableHeader)
Sets the tableHeader working with this JTable to newHeader.
 o setUI(TableUI)
 o setValueAt(Object, int, int)
Sets the value for the cell at columnIndex and rowIndex.
 o setValueAt(Object, Object, int)
Sets the value for the cell at columnIdentifier and rowIndex.
 o sizeColumnsToFit(boolean)
This method will resize one or more columns of the table so that the sum width of all columns will equal to the width of the table.
 o tableChanged(TableModelEvent)
 o tableRowsInserted(TableModelEvent)
 o tableRowsRemoved(TableModelEvent)
 o updateUI()
Called to replace the UI with the latest version from the default UIFactory.
 o valueChanged(ListSelectionEvent)

Variables

 o AUTO_RESIZE_OFF
 public static final int AUTO_RESIZE_OFF
Do not auto resize column when table is resized.

 o AUTO_RESIZE_LAST_COLUMN
 public static final int AUTO_RESIZE_LAST_COLUMN
Auto resize last column only when table is resized

 o AUTO_RESIZE_ALL_COLUMNS
 public static final int AUTO_RESIZE_ALL_COLUMNS
Proportionately resize all columns when table is resized

 o dataModel
 protected TableModel dataModel
The TableModel of the table

 o columnModel
 protected TableColumnModel columnModel
The TableColumnModel of the table

 o selectionModel
 protected ListSelectionModel selectionModel
The ListSelectionModel of the table, used to keep track of row selections

 o tableHeader
 protected JTableHeader tableHeader
The TableHeader working with the table

 o rowHeight
 protected int rowHeight
The height of all rows in the table

 o rowMargin
 protected int rowMargin
The height margin between rows

 o gridColor
 protected Color gridColor
The color of the grid

 o showGrid
 protected boolean showGrid
The table draws a grid between cells if showGrid is true

 o autoResizeMode
 protected int autoResizeMode
This mode value determines if table automatically resizes the width the table's columns to take up the entire width of the table, and how it does the resizing.

 o autoCreateColumnsFromModel
 protected boolean autoCreateColumnsFromModel
The table will query the TableModel to build the default set of columns if this is true.

 o preferredViewportSize
 protected Dimension preferredViewportSize
Used by the Scrollable interface to determine the initial visible area

 o multipleSelectionAllowed
 protected boolean multipleSelectionAllowed
Multiple rows selected allowed in this table

 o emptySelectionAllowed
 protected boolean emptySelectionAllowed
Empty selection allowed in this table

 o rowSelectionAllowed
 protected boolean rowSelectionAllowed
Row selection allowed in this table

 o simultaneousRowColumnSelectionAllowed
 protected boolean simultaneousRowColumnSelectionAllowed
If this is true, then both a row selection and a column selection can be non-empty at the same time. Typically, when you select one the other is deselected.

 o isRowSelected
 protected boolean isRowSelected
 o cellEditor
 protected transient TableCellEditor cellEditor
 o editingColumn
 protected transient int editingColumn
 o editingRow
 protected transient int editingRow
 o editorComp
 protected transient Component editorComp
If editing, Component that is handling the editing.

Constructors

 o JTable
 public JTable()
Constructs a default JTable which is initialized with a default data model, a default column model, and a default selection model.

See Also:
createDefaultDataModel, createDefaultColumnModel, createDefaultSelectionModel
 o JTable
 public JTable(TableModel dm)
Constructs a JTable which is initialized with dm as the data model, a default column model, and a default selection model.

Parameters:
dm - The data model for the table
See Also:
createDefaultColumnModel, createDefaultSelectionModel
 o JTable
 public JTable(TableModel dm,
               TableColumnModel cm)
Constructs a JTable which is initialized with dm as the data model, cm as the column model, and a default selection model.

Parameters:
dm - The data model for the table
cm - The column model for the table
See Also:
createDefaultSelectionModel
 o JTable
 public JTable(TableModel dm,
               TableColumnModel cm,
               ListSelectionModel sm)
Constructs a JTable which is initialized with dm as the data model, cm as the column model, and sm as the selection model. If any of the parameters are null this method will initialize the table with the corresponding default model.

Parameters:
dm - The data model for the table
cm - The column model for the table
sm - The row selection model for the table
See Also:
createDefaultDataModel, createDefaultColumnModel, createDefaultSelectionModel
 o JTable
 public JTable(int numColumns,
               int numRows)
Constructs a JTable with numColumns and numRows of empty cells using the DefaultTableModel. The columns will have names of the form "Column0", "Column1", "Column2", etc.

Parameters:
numColumns - The number of columns the table holds
numRows - The number of rows the table holds
See Also:
DefaultTableModel
 o JTable
 public JTable(Vector data,
               Vector columnNames)
Constructs a JTable using a DefaultTableModel and initialize the table with the values in the data Vector. The vectors contained in the outer vector should each contain a single row of values. In other words, the value of the cell at column 5, row 1 can be obtain with the follow code:

((Vector)data.elementAt(1)).elementAt(5);

Parameters:
data - The data for the new table
columnNames - Names of each column
Throws: IllegalArgumentException
if data is null or if the number of columns in data does not equal the number of names in columnNames.
 o JTable
 public JTable(Object data[][],
               Object columnNames[])
Constructs a JTable using a DefaultTableModel and initialize the table with the values in the data array. The first index in the Object[][] is the row index and the second is the column index.

Parameters:
data - The data for the new table
columnNames - Names of each column
Throws: IllegalArgumentException
if data is null or if the number of columns in data does not equal the number of names in columnNames.

Methods

 o createScrollPaneForTable
 public static JScrollPane createScrollPaneForTable(JTable aTable)
This static method is provided to simplify the task of wrapping a JTable in a scroll pane. This method will take care of putting the table and its header in the correct place. If aTable is null this will create a default JTable.

Parameters:
aTable - The table to install in a scrollPane.
 o setTableHeader
 public void setTableHeader(JTableHeader newHeader)
Sets the tableHeader working with this JTable to newHeader. It is legal to have a null tableHeader.

Parameters:
newHeader - new tableHeader
See Also:
getTableHeader
 o getTableHeader
 public JTableHeader getTableHeader()
Returns the tableHeader working with this JTable.

Returns:
the tableHeader working with the receiver
See Also:
setTableHeader
 o setRowHeight
 public void setRowHeight(int newHeight)
Sets the height for rows to newRowHeight and invokes tile

Parameters:
newRowHeight - new row height
Throws: IllegalArgumentException
If newRowHeight is less than 1.
See Also:
getRowHeight
 o getRowHeight
 public int getRowHeight()
Returns the height of a table row in the receiver. The default row height is 16.0.

Returns:
the height of each row in the receiver
See Also:
setRowHeight
 o setIntercellSpacing
 public void setIntercellSpacing(Dimension newSpacing)
Sets the width and height between cells to newSpacing and redisplays the receiver.

Parameters:
newSpacing - The new width and height intercellSpacing
See Also:
getIntercellSpacing
 o getIntercellSpacing
 public Dimension getIntercellSpacing()
Returns the horizontal and vertical spacing between cells. The default spacing is (3, 2).

Returns:
the horizontal and vertical spacing between cells
See Also:
setIntercellSpacing
 o setGridColor
 public void setGridColor(Color newColor)
Sets the color used to draw grid lines to color and redisplays the receiver. The default color is gray.

Parameters:
color - new color of the grid
Throws: IllegalArgumentException
if color is null
See Also:
getGridColor
 o getGridColor
 public Color getGridColor()
Returns the color used to draw grid lines. The default color is gray.

Returns:
the color used to draw grid lines
See Also:
setGridColor
 o setShowGrid
 public void setShowGrid(boolean b)
Sets whether the receiver draws grid lines around cells. If flag is true it does; if it is false it doesn't.

Parameters:
flag - true if table view should draw grid lines
See Also:
getShowGrid
 o getShowGrid
 public boolean getShowGrid()
Returns true if the receiver draws grid lines around cells, false if it doesn't. The default is true.

Returns:
true if the receiver draws grid lines around cells, false if it doesn't
See Also:
setShowGrid
 o setAutoResizeMode
 public void setAutoResizeMode(int mode)
Sets the table's auto resize mode when the table is resized.

Parameters:
mode - One of 3 legal values: AUTO_RESIZE_OFF, AUTO_RESIZE_LAST_COLUMN, AUTO_RESIZE_ALL_COLUMNS
See Also:
getAutoResizeMode, sizeColumnsToFit
 o getAutoResizeMode
 public int getAutoResizeMode()
Returns auto resize mode of the table. The default is AUTO_RESIZE_ALL_COLUMNS.

Returns:
the autoResizeMode of the table
See Also:
setAutoResizeMode, sizeColumnsToFit
 o setAutoCreateColumnsFromModel
 public void setAutoCreateColumnsFromModel(boolean createColumns)
Sets the table's autoCreateColumnsFromModel flag. This method will call createDefaultColumnsFromModel() if createColumns is true.

Parameters:
createColumns - true if JTable should auto create columns
See Also:
getAutoCreateColumnsFromModel, createDefaultColumnsFromModel
 o getAutoCreateColumnsFromModel
 public boolean getAutoCreateColumnsFromModel()
Returns whether the table will create default columns from the model. If this is true, setModel() will clear any existing columns and create new columns from the new model. Also if the event in the the tableChanged() notification specified the entired table changed then the columns will be rebuilt. The default is true.

Returns:
the autoCreateColumnsFromModel of the table
See Also:
setAutoCreateColumnsFromModel, createDefaultColumnsFromModel
 o createDefaultColumnsFromModel
 public void createDefaultColumnsFromModel()
This method will create default columns for the table from the data model using the getColumnCount(), getColumnIdentifier(), and getColumnType() methods defined in the TableModel interface.

This method will clear any exsiting columns before creating the new columns based on information from the model.

See Also:
getAutoCreateColumnsFromModel
 o setMultipleSelectionAllowed
 public void setMultipleSelectionAllowed(boolean flag)
Sets whether the user can select more than one column or row at a time.

See Also:
getMultipleSelectionAllowed
 o getMultipleSelectionAllowed
 public boolean getMultipleSelectionAllowed()
Returns:
true if the receiver allows more than one column or row selected
See Also:
setMultipleSelectionAllowed
 o setEmptySelectionAllowed
 public void setEmptySelectionAllowed(boolean flag)
Sets whether the user can select zero columns or rows.

See Also:
getEmptySelectionAllowed
 o getEmptySelectionAllowed
 public boolean getEmptySelectionAllowed()
Returns:
true if the receiver allows zero column or rows selected
See Also:
setEmptySelectionAllowed
 o setRowSelectionAllowed
 public void setRowSelectionAllowed(boolean flag)
Sets whether the rows in this model can be selected.

See Also:
getRowSelectionAllowed
 o getRowSelectionAllowed
 public boolean getRowSelectionAllowed()
Returns:
true if rows can be selected.
See Also:
setRowSelectionAllowed
 o setColumnSelectionAllowed
 public void setColumnSelectionAllowed(boolean flag)
Sets whether the columns in this model can be selected.

See Also:
getColumnSelectionAllowed
 o getColumnSelectionAllowed
 public boolean getColumnSelectionAllowed()
Returns:
true if columns can be selected.
See Also:
setColumnSelectionAllowed
 o setSimultaneousRowColumnSelectionAllowed
 public void setSimultaneousRowColumnSelectionAllowed(boolean flag)
Sets whether this table allows both a column selection and a row selection to exist at the same time. The default is false, which means, when the user selects a column all rows are deselected, and vice versa.

See Also:
getSimultaneousRowColumnSelectionAllowed
 o getSimultaneousRowColumnSelectionAllowed
 public boolean getSimultaneousRowColumnSelectionAllowed()
Returns:
true if simultaneous row and column selections are allowed
See Also:
setSimultaneousRowColumnSelectionAllowed
 o selectAll
 public void selectAll()
If a column is selected, then this selects all columns. Similarly, if a row is selected, then, this selects all rows. If both a column and a row are selected at the time this method is invoked, then all columns and rows are selected.

 o clearSelection
 public void clearSelection()
Deselects all selected columns and rows. If empty selection is not allowed, then it leaves the first row selected.

 o setRowSelectionInterval
 public void setRowSelectionInterval(int index0,
                                     int index1)
Selects the rows from index0 to index1 inclusive, if row selection is allowed. If multiple selection is not allowed then it only selects the row at index0.

Parameters:
index0 - one end of the interval.
index1 - other end of the interval
 o setColumnSelectionInterval
 public void setColumnSelectionInterval(int index0,
                                        int index1)
Selects the columns from index0 to index1 inclusive, if column selection is allowed. If multiple selection is not allowed then it only selects the column at index0.

Parameters:
index0 - one end of the interval.
index1 - other end of the interval
 o addRowSelectionInterval
 public void addRowSelectionInterval(int index0,
                                     int index1)
Adds the rows from index0 to index0 inclusive to the current selection, if row selection and multiple selection is allowed.

Parameters:
index0 - one end of the interval.
index1 - other end of the interval
 o addColumnSelectionInterval
 public void addColumnSelectionInterval(int index0,
                                        int index1)
Adds the columns from index0 to index0 inclusive to the current selection, if column selection and multiple selection is allowed.

Parameters:
index0 - one end of the interval.
index1 - other end of the interval
 o removeRowSelectionInterval
 public void removeRowSelectionInterval(int index0,
                                        int index1)
Deselects the rows from index0 to index0 inclusive. If empty selection is not allowed then this might leave one row selected.

Parameters:
index0 - one end of the interval.
index1 - other end of the interval
 o removeColumnSelectionInterval
 public void removeColumnSelectionInterval(int index0,
                                           int index1)
Deselects the columns from index0 to index0 inclusive. If empty selection is not allowed then this might leave one column selected.

Parameters:
index0 - one end of the interval.
index1 - other end of the interval
 o getSelectedRow
 public int getSelectedRow()
Returns:
the index of the last row selected or added to the selection, (lead selection) or -1 if no row is selected.
See Also:
getSelectedRows
 o getSelectedColumn
 public int getSelectedColumn()
Returns:
the index of the last column selected or added to the selection, (lead selection) or -1 if no column is selected.
See Also:
getSelectedColumns
 o getSelectedRows
 public int[] getSelectedRows()
Returns:
the indices of all selected rows, or an empty int array if no row is selected.
See Also:
getSelectedRow
 o getSelectedColumns
 public int[] getSelectedColumns()
Returns:
the indices of all selected columns, or an empty int array if no column is selected.
See Also:
getSelectedColumn
 o getSelectedRowCount
 public int getSelectedRowCount()
Returns:
the number of selected rows. 0 if no columns are selected.
 o getSelectedColumnCount
 public int getSelectedColumnCount()
Returns:
the number of selected columns. 0 if no columns are selected.
 o isRowSelected
 public boolean isRowSelected(int row)
Returns:
true if the row at index row is selected
Throws: IllegalArgumentException
if row is not in the valid range
 o isColumnSelected
 public boolean isColumnSelected(int column)
Returns:
true if the column at index column is selected
Throws: IllegalArgumentException
if column is not in the valid range
 o isColumnSelected
 public boolean isColumnSelected(Object identifier)
Returns:
true if the column with an identifier matching identifer is selected
 o getColumnCount
 public int getColumnCount()
Returns the number of columns in the table

Returns:
the number of columns in the table
See Also:
getRowCount
 o getColumn
 public TableColumn getColumn(Object identifier)
Returns the TableColumn object for the column in the table whose identifier is equal to identifier, when compared using equals(). Returns null if no matching column is found.

Parameters:
identifier - the identifier object
Returns:
the TableColumn object with matching identifier
 o getRowCount
 public int getRowCount()
Returns the number of rows in the table.

See Also:
getColumnCount
 o getValueAt
 public Object getValueAt(Object columnIdentifier,
                          int rowIndex)
Returns the cell value at columnIdentifier and rowIndex.

Parameters:
columnIdentifier - the column whose value is to be looked up
rowIndex - the row whose value is to be looked up
Returns:
the value Object at the specified cell
 o getValueAt
 public Object getValueAt(int columnIndex,
                          int rowIndex)
Returns the cell value at columnIndex and rowIndex.

NOTE: The columnIndex is specified in the table view's display order, and not in the TableModel's column order. This is an important distinction because as the user rearranges the columns in the table, what is at column 2 changes. Meanwhile the user's action never effect the model's column ordering.

Parameters:
columnIndex - the column whose value is to be looked up
rowIndex - the row whose value is to be looked up
Returns:
the value Object at the specified cell
 o isCellEditable
 public boolean isCellEditable(Object columnIdentifier,
                               int rowIndex)
Returns true if the cell at columnIdentifier and rowIndex is editable. Otherwise, setValueAt() on the cell will not change the value of that cell.

Parameters:
columnIdentifier - the column whose value is to be looked up
rowIndex - the row whose value is to be looked up
Returns:
true if the cell is editable.
See Also:
setValueAt
 o isCellEditable
 public boolean isCellEditable(int columnIndex,
                               int rowIndex)
Returns true if the cell at columnIndex and rowIndex is editable. Otherwise, setValueAt() on the cell will not change the value of that cell.

Parameters:
columnIndex - the column whose value is to be looked up
rowIndex - the row whose value is to be looked up
Returns:
true if the cell is editable.
See Also:
setValueAt
 o setValueAt
 public void setValueAt(Object aValue,
                        Object columnIdentifier,
                        int rowIndex)
Sets the value for the cell at columnIdentifier and rowIndex. aValue is the new value.

Parameters:
aValue - the new value
columnIdentifier - the column whose value is to be changed
rowIndex - the row whose value is to be changed
See Also:
getValueAt
 o setValueAt
 public void setValueAt(Object aValue,
                        int columnIndex,
                        int rowIndex)
Sets the value for the cell at columnIndex and rowIndex. aValue is the new value.

Parameters:
aValue - the new value
columnIndex - the column whose value is to be changed
rowIndex - the row whose value is to be changed
See Also:
getValueAt
 o addColumn
 public void addColumn(TableColumn aColumn)
Appends aColumn to the end of the JTable's array of columns.

Parameters:
aColumn - The TableColumn to be added
 o addColumn
 public TableColumn addColumn(Object columnIdentifier,
                              Vector columnData)
Add a column to the table. The new column will have the unique identifier columnIdentifier. columnData is the optional Vector of data for the column. If it is null the column is filled with null values.

Parameters:
columnIdentifier - the unique object identifier of the column
columnData - optional data of the column being added
Throws: IllegalArgumentException
if columnIdentifier is null
Throws: InternalError
if dataModel is not a DefaultTableModel
 o addColumn
 public TableColumn addColumn(Object columnIdentifier,
                              int width)
 o addColumn
 public TableColumn addColumn(Object columnIdentifier,
                              int width,
                              TableCellRenderer renderer,
                              TableCellEditor editor)
 o addColumn
 public TableColumn addColumn(Object columnIdentifier,
                              int width,
                              TableCellRenderer renderer,
                              TableCellEditor editor,
                              Vector columnData)
Creates a new column with columnIdentifier, width, renderer, and editor to the end of the JTable's array of columns. columnData is the optional Vector of data for the column. If it is null the column is filled with null values.

Note: By default, the columnIdentifier's toString() value is used as the name of the column. If that is not the desired name for the column, the name can be changed using TableColumn's setHeaderValue() method.

Parameters:
columnIdentifier - The unique identifier of the new column
width - The new column's width. Or -1 to use the default width
renderer - The renderer used with the new column. Or null to use the default renderer.
editor - The editor used with the new column. Or null to use the default editor.
columnData - optional data of the column being added
Throws: InternalError
if dataModel is not a DefaultTableModel
 o removeColumn
 public void removeColumn(TableColumn aColumn)
Removes aColumn from the JTable's array of columns.

Parameters:
aColumn - The TableColumn to be removed
 o removeColumn
 public void removeColumn(Object columnIdentifier)
Remove the column with an identifier that matches the parameter columnIdentifier.

Parameters:
columnIdentifier - the identifier of the column being removed
Throws: InternalError
if dataModel is not a DefaultTableModel
 o moveColumn
 public void moveColumn(Object columnIdentifier,
                        Object targetColumnIdentifier)
Moves the column and heading at with the unique id columnIdentifier to the position currently occupied by the column with the unique id targetColumnIdentifier. The old column at targetColumnIdentifier is shifted left or right to make room. This will not move any columns if columnIdentifier equals targetColumnIdentifier.

Parameters:
columnIdentifier - the index of column to be moved
targetColumnIdentifier - New index to move the column
Throws: IllegalArgumentException
if columnIdentifier or targetColumnIdentifier are not found
 o addRow
 public void addRow(Vector rowData)
Add a row to the table. The new row will contain empty values unless rowData is specified.

Parameters:
rowData - optional data of the row being added
Throws: InternalError
if dataModel is not a DefaultTableModel
 o addRow
 public void addRow(Object rowData[])
Add a row to the table. The new row will contain empty values unless rowData is specified.

Parameters:
rowData - optional data of the row being added
Throws: InternalError
if dataModel is not a DefaultTableModel
 o insertRow
 public void insertRow(int rowIndex,
                       Vector rowData)
Insert a row at rowIndex in the table. The new row will contain empty values unless rowData is specified.

Parameters:
rowIndex - the row index of the row to be inserted
rowData - optional data of the row being added
Throws: ArrayIndexOutOfBoundsException
if the rowIndex was invalid.
Throws: InternalError
if dataModel is not a DefaultTableModel
 o insertRow
 public void insertRow(int rowIndex,
                       Object rowData[])
Insert a row at rowIndex in the table. The new row will contain empty values unless rowData is specified.

Parameters:
rowIndex - the row index of the row to be inserted
rowData - optional data of the row being added
Throws: ArrayIndexOutOfBoundsException
if the rowIndex was invalid.
Throws: InternalError
if dataModel is not a DefaultTableModel
 o removeRow
 public void removeRow(int rowIndex)
Remove the row at rowIndex from the table.

Parameters:
rowIndex - the row index of the row to be removed
Throws: ArrayIndexOutOfBoundsException
if the rowIndex was invalid.
Throws: InternalError
if dataModel is not a DefaultTableModel
 o moveRow
 public void moveRow(int startIndex,
                     int endIndex,
                     int toIndex)
Moves one or more rows starting at startIndex to endIndex in the model to the toIndex.

Parameters:
startIndex - the starting row index to be moved
endIndex - the ending row index to be moved
toIndex - the destination of the rows to be moved
Throws: ArrayIndexOutOfBoundsException
if any of the indices are out of range.
Throws: InternalError
if dataModel is not a DefaultTableModel
 o setNumRows
 public void setNumRows(int newSize)
Sets the number of rows in the table. If the new size is greater than the current size, new rows are added to the end of the model If the new size is less than the current size, all rows at index newSize and greater are discarded.

Parameters:
newSize - the new number of rows
Throws: InternalError
if dataModel is not a DefaultTableModel
 o setDataVector
 public void setDataVector(Vector newData,
                           Vector columnIds)
 o setDataVector
 public void setDataVector(Object newData[][],
                           Object columnIds[])
 o columnAtPoint
 public int columnAtPoint(Point point)
Returns the index of the column that point lies in, or -1 if it lies outside the receiver's bounds.

Returns:
the index of the column that point lies in, or -1 if it lies outside the receiver's bounds
See Also:
rowAtPoint
 o rowAtPoint
 public int rowAtPoint(Point point)
Returns the index of the row that point lies in, or -1 if it lies outside the receiver's bounds.

Returns:
the index of the row that point lies in, or -1 if it lies outside the receiver's bounds
See Also:
columnAtPoint
 o getCellRect
 public Rectangle getCellRect(int column,
                              int row,
                              boolean includeSpacing)
Returns a rectangle locating the cell that lies at the intersection of column and row. If includeSpacing is true then the value returned includes the intercellSpacing margin. If it is false, then the returned rect is inset by half of intercellSpacing. (This is the true frame of the cell)

Parameters:
column - the column to compute
row - the row to compute
includeSpacing - if true, the rect returned will include the correct intercellSpacing
Returns:
the rectangle containing the cell at index column,row
Throws: IllegalArgumentException
If column or row are not in the valid range.
 o sizeColumnsToFit
 public void sizeColumnsToFit(boolean lastColumnOnly)
This method will resize one or more columns of the table so that the sum width of all columns will equal to the width of the table. If lastColumnOnly is true, then it will try to resize the last column only to make it fit, but if it runs into either the minimum size limit of the column or maximum size limit, then it will change the next to last column also, etc. If lastColumnOnly is false, then it will spread the size delta proportionately to all the columns, while respecting each column's max and min size limits. Also, notifications of each column width change will be sent out as they are resized.

Note: It is possible that even after this method is called, the total width of the columns is still not be equal to the width of the table. eg. A table with a single column, the column has a minimum width of 20, and the tableView has a width of 10. And there is nothing I can do about that.

Parameters:
lastColumnOnly - Try to change the last column only if true
See Also:
setWidth
 o setBounds
 public void setBounds(int x,
                       int y,
                       int w,
                       int h)
Overriding setBounds() to call sizeColumnsToFit() depending on the setting of autoResizeMode

Overrides:
setBounds in class JComponent
 o getToolTipText
 public String getToolTipText(MouseEvent event)
Overriding to allow renderer's tips to be used if it has text set.

NOTE: For JTable to properly display tooltips of its renderers JTable must be a registered component with the ToolTipManager. This is done automatically in initializeLocalVars(), but if at a later point if JTable is told setToolTipText(null) it will unregister the table component, and no tips from renderers will display anymore.

Overrides:
getToolTipText in class JComponent
 o editColumnRow
 public boolean editColumnRow(int columnIndex,
                              int rowIndex)
Programmatically starts editing the cell at column and row, if the cell is editable.

Parameters:
columnIndex - the index of column to be edited
rowIndex - the index of row to be edited
Returns:
false if for any reason the cell cannot be edited.
Throws: IllegalArgumentException
If column or row are not in the valid range
 o editColumnRow
 public boolean editColumnRow(int columnIndex,
                              int rowIndex,
                              EventObject e)
Programmatically starts editing the cell at column and row, if the cell is editable. The EventObject e is passed into the CellEditor's method shouldSelectCell and isCellEditable.

Parameters:
columnIndex - the index of column to be edited
rowIndex - the index of row to be edited
e - event to pass into shouldSelectCell
Returns:
false if for any reason the cell cannot be edited.
Throws: IllegalArgumentException
If column or row are not in the valid range
 o editColumnRow
 public boolean editColumnRow(Object identifier,
                              int row)
Programmatically starts editing the cell at column with identifier and row, if the cell is editable.

Parameters:
identifier - the index of column to be edited
row - the index of row to be edited
Returns:
false if for any reason the cell cannot be edited.
Throws: IllegalArgumentException
If identifier is not found or row is not in the valid range
 o isEditing
 public boolean isEditing()
Returns:
true is the table is editing a cell
See Also:
editingColumn, editingRow
 o getEditorComponent
 public Component getEditorComponent()
If the receiver is currently editing this will return the Component that was returned from the CellEditor.

Returns:
Component handling editing session
 o editingColumn
 public int editingColumn()
If sent while isEditing() is true, this returns the index of the editing column; otherwise returns -1.

Returns:
the index of the column being edited; otherwise returns -1
See Also:
editingRow
 o editingRow
 public int editingRow()
If sent while isEditing() is true, this returns the index of the editing row; otherwise returns -1.

Returns:
the index of the row being edited; otherwise returns -1
See Also:
editingColumn
 o getUI
 public TableUI getUI()
 o setUI
 public void setUI(TableUI ui)
 o updateUI
 public void updateUI()
Called to replace the UI with the latest version from the default UIFactory.

Overrides:
updateUI in class JComponent
 o getUIClassID
 public String getUIClassID()
Returns:
"TableUI"
Overrides:
getUIClassID in class JComponent
See Also:
getUIClassID, getUI
 o setModel
 public void setModel(TableModel newModel)
Sets the data model for this table to newModel and registers with for listner notifications from the new data model.

Parameters:
newModel - the new data source for this table
Throws: IllegalArgumentException
if newModel is null
See Also:
getModel
 o getModel
 public TableModel getModel()
Returns the TableModel that provides the data displayed by the receiver.

Returns:
the object that provides the data displayed by the receiver
See Also:
setModel
 o setColumnModel
 public void setColumnModel(TableColumnModel newModel)
Sets the column model for this table to newModel and registers with for listner notifications from the new column model.

Parameters:
newModel - the new data source for this table
Throws: IllegalArgumentException
if newModel is null
See Also:
getColumnModel
 o getColumnModel
 public TableColumnModel getColumnModel()
Returns the TableColumnModel that contains all column inforamtion of this table.

Returns:
the object that provides the column state of the table
See Also:
setColumnModel
 o setSelectionModel
 public void setSelectionModel(ListSelectionModel newModel)
Sets the row selection model for this table to newModel and registers with for listner notifications from the new selection model. If newModel is null, it means the rows in this table are not selectable.

Parameters:
newModel - the new selection model
See Also:
getSelectionModel
 o getSelectionModel
 public ListSelectionModel getSelectionModel()
Returns the ListSelectionModel that is used to maintain row selection state.

Returns:
the object that provides row selection state. Or null if row selection is not allowed.
See Also:
setSelectionModel
 o tableChanged
 public void tableChanged(TableModelEvent e)
 o tableRowsInserted
 public void tableRowsInserted(TableModelEvent e)
 o tableRowsRemoved
 public void tableRowsRemoved(TableModelEvent e)
 o columnAdded
 public void columnAdded(TableColumnModelEvent e)
 o columnRemoved
 public void columnRemoved(TableColumnModelEvent e)
 o columnMoved
 public void columnMoved(TableColumnModelEvent e)
 o columnMarginChanged
 public void columnMarginChanged(ChangeEvent e)
 o columnSelectionChanged
 public void columnSelectionChanged(ListSelectionEvent e)
 o valueChanged
 public void valueChanged(ListSelectionEvent e)
 o editingStopped
 public void editingStopped(ChangeEvent e)
 o editingCanceled
 public void editingCanceled(ChangeEvent e)
 o getPreferredScrollableViewportSize
 public void getPreferredScrollableViewportSize(Dimension size)
 o getPreferredScrollableViewportSize
 public Dimension getPreferredScrollableViewportSize()
 o getScrollableUnitIncrement
 public int getScrollableUnitIncrement(Rectangle visibleRect,
                                       int orientation,
                                       int direction)
 o getScrollableBlockIncrement
 public int getScrollableBlockIncrement(Rectangle visibleRect,
                                        int orientation,
                                        int direction)
Returns:
The visibleRect.height or visibleRect.width per the orientation.
 o getScrollableTracksViewportWidth
 public boolean getScrollableTracksViewportWidth()
 o getScrollableTracksViewportHeight
 public boolean getScrollableTracksViewportHeight()
 o initializeLocalVars
 protected void initializeLocalVars()
 o createDefaultDataModel
 protected TableModel createDefaultDataModel()
Returns the default table model object which is a DefaultTableModel. Subclass can override this method to return a different table model object

Returns:
the default table model object
 o createDefaultColumnModel
 protected TableColumnModel createDefaultColumnModel()
Returns the default column model object which is a DefaultTableColumnModel. Subclass can override this method to return a different column model object

Returns:
the default column model object
 o createDefaultSelectionModel
 protected ListSelectionModel createDefaultSelectionModel()
Returns the default selection model object which is a DefaultListSelectionModel. Subclass can override this method to return a different selection model object

Returns:
the default selection model object
 o createDefaultTableHeader
 protected JTableHeader createDefaultTableHeader()
Returns the default table header object which is a JTableHeader. Subclass can override this method to return a different table header object

Returns:
the default table header object
 o resizeAndRepaint
 protected void resizeAndRepaint()
Properly sizes the receiver and its header view, and marks it as needing display. Also resets cursor rectangles for the header view and line scroll amounts for the JScrollPane.

 o resizeAndRepaint
 protected void resizeAndRepaint(int x,
                                 int y,
                                 int w,
                                 int h)
Properly sizes the receiver and its header view, and marks it as needing display. Also resets cursor rectangles for the header view and line scroll amounts for the JScrollPane.

 o getCellEditor
 public TableCellEditor getCellEditor()
Set the cellEditor variable

 o setCellEditor
 public void setCellEditor(TableCellEditor anEditor)
Set the cellEditor variable

 o setEditingColumn
 public void setEditingColumn(int aColumn)
Set the editingColumn variable

 o setEditingRow
 public void setEditingRow(int aRow)
Set the editingRow variable

 o isOpaque
 public boolean isOpaque()
Returns true if this component is completely opaque.

Overrides:
isOpaque in class JComponent
 o prepareEditor
 public Component prepareEditor(TableCellEditor editor,
                                TableColumn aColumn,
                                int row)
 o removeEditor
 public void removeEditor()
 o checkDefaultTableModel
 protected void checkDefaultTableModel()
Checks the table model. If it is not a DefaultTableModel this throws an InternalError exception.


All Packages  Class Hierarchy  This Package  Previous  Next  Index