JTable is used to display and edit regular two-dimensional tables
of cells.
See How to Use Tables
in The Java Tutorial
for task-oriented documentation and examples of using JTable.
The JTable has many
facilities that make it possible to customize its rendering and editing
but provides defaults for these features so that simple tables can be
set up easily. For example, to set up a table with 10 rows and 10
columns of numbers:
TableModel dataModel = new AbstractTableModel() {
public int getColumnCount() { return 10; }
public int getRowCount() { return 10;}
public Object getValueAt(int row, int col) { return Integer.valueOf(row*col); }
};
JTable table = new JTable(dataModel);
JScrollPane scrollpane = new JScrollPane(table);
JTables are typically placed inside of a JScrollPane. By
default, a JTable will adjust its width such that
a horizontal scrollbar is unnecessary. To allow for a horizontal scrollbar,
invoke setAutoResizeMode with AUTO_RESIZE_OFF.
Note that if you wish to use a JTable in a standalone
view (outside of a JScrollPane) and want the header
displayed, you can get it using getTableHeader and
display it separately.
To enable sorting and filtering of rows, use a
RowSorter.
You can set up a row sorter in either of two ways:
RowSorter. For example:
table.setRowSorter(new TableRowSorter(model)).
autoCreateRowSorter
property to true, so that the JTable
creates a RowSorter for
you. For example: setAutoCreateRowSorter(true).
When designing applications that use the JTable it is worth paying
close attention to the data structures that will represent the table's data.
The DefaultTableModel is a model implementation that
uses a Vector of Vectors of Objects to
store the cell values. As well as copying the data from an
application into the DefaultTableModel,
it is also possible to wrap the data in the methods of the
TableModel interface so that the data can be passed to the
JTable directly, as in the example above. This often results
in more efficient applications because the model is free to choose the
internal representation that best suits the data.
A good rule of thumb for deciding whether to use the AbstractTableModel
or the DefaultTableModel is to use the AbstractTableModel
as the base class for creating subclasses and the DefaultTableModel
when subclassing is not required.
The "TableExample" directory in the demo area of the source distribution
gives a number of complete examples of JTable usage,
covering how the JTable can be used to provide an
editable view of data taken from a database and how to modify
the columns in the display to use specialized renderers and editors.
The JTable uses integers exclusively to refer to both the rows and the columns
of the model that it displays. The JTable simply takes a tabular range of cells
and uses getValueAt(int, int) to retrieve the
values from the model during painting. It is important to remember that
the column and row indexes returned by various JTable methods
are in terms of the JTable (the view) and are not
necessarily the same indexes used by the model.
By default, columns may be rearranged in the JTable so that the
view's columns appear in a different order to the columns in the model.
This does not affect the implementation of the model at all: when the
columns are reordered, the JTable maintains the new order of the columns
internally and converts its column indices before querying the model.
So, when writing a TableModel, it is not necessary to listen for column
reordering events as the model will be queried in its own coordinate
system regardless of what is happening in the view.
In the examples area there is a demonstration of a sorting algorithm making
use of exactly this technique to interpose yet another coordinate system
where the order of the rows is changed, rather than the order of the columns.
Similarly when using the sorting and filtering functionality
provided by RowSorter the underlying
TableModel does not need to know how to do sorting,
rather RowSorter will handle it. Coordinate
conversions will be necessary when using the row based methods of
JTable with the underlying TableModel.
All of JTables row based methods are in terms of the
RowSorter, which is not necessarily the same as that
of the underlying TableModel. For example, the
selection is always in terms of JTable so that when
using RowSorter you will need to convert using
convertRowIndexToView or
convertRowIndexToModel. The following shows how to
convert coordinates from JTable to that of the
underlying model:
int[] selection = table.getSelectedRows();
for (int i = 0; i < selection.length; i++) {
selection[i] = table.convertRowIndexToModel(selection[i]);
}
// selection is now in terms of the underlying TableModel
By default if sorting is enabled JTable will persist the
selection and variable row heights in terms of the model on
sorting. For example if row 0, in terms of the underlying model,
is currently selected, after the sort row 0, in terms of the
underlying model will be selected. Visually the selection may
change, but in terms of the underlying model it will remain the
same. The one exception to that is if the model index is no longer
visible or was removed. For example, if row 0 in terms of model
was filtered out the selection will be empty after the sort.
J2SE 5 adds methods to JTable to provide convenient access to some
common printing needs. Simple new print() methods allow for quick
and easy addition of printing support to your application. In addition, a new
getPrintable method is available for more advanced printing needs.
As for all JComponent classes, you can use
InputMap and ActionMap to associate an
Action object with a KeyStroke and execute the
action under specified conditions.
Warning
Swing is not thread safe. For more information see Swing's Threading Policy.
Warning
Serialized objects of this class will not be compatible with
future Swing releases. The current serialization support is
appropriate for short term storage or RMI between applications running
the same version of Swing. As of 1.4, support for long term storage
of all JavaBeans
has been added to the java.beans package.
Please see java..
javax.swing.table.DefaultTableModel , javax.swing.table.TableRowSorter
| Modifier and Type | Class and Description |
|---|---|
| protected class | JTable.
This class implements accessibility support for the
|
| pack-priv static class | |
| pack-priv static class | |
| pack-priv class | |
| pack-priv static class | |
| pack-priv static class | |
| public static class | JTable.
A subclass of |
| pack-priv static class | JTable.
Default Editors |
| pack-priv static class | |
| private class | JTable.
ModelChange is used when sorting to restore state, it corresponds to data from a TableModelEvent. |
| pack-priv static class | |
| pack-priv static class | JTable.
Default Renderers |
| public static enum | JTable.
Printing modes, used in printing |
| private static interface | |
| private static interface | |
| private class | JTable.
SortManager provides support for managing the selection and variable row heights when sorting is enabled. |
| private static class | JTable.
A |
| Modifier and Type | Field and Description |
|---|---|
| public static final int | AUTO_RESIZE_ALL_COLUMNS
During all resize operations, proportionately resize all columns. |
| public static final int | AUTO_RESIZE_LAST_COLUMN
During all resize operations, apply adjustments to the last column only. |
| public static final int | AUTO_RESIZE_NEXT_COLUMN
When a column is adjusted in the UI, adjust the next column the opposite way. |
| public static final int | AUTO_RESIZE_OFF
Do not adjust column widths automatically; use a horizontal scrollbar instead. |
| public static final int | AUTO_RESIZE_SUBSEQUENT_COLUMNS
During UI adjustment, change subsequent columns to preserve the total width; this is the default behavior. |
| protected boolean | autoCreateColumnsFromModel
The table will query the |
| private boolean | autoCreateRowSorter
If true, any time the model changes a new RowSorter is set. |
| protected int | autoResizeMode
Determines if the table automatically resizes the width of the table's columns to take up the entire width of the table, and how it does the resizing. |
| protected transient TableCellEditor | cellEditor
The active cell editor object, that overwrites the screen real estate occupied by the current cell and allows the user to change its contents. |
| protected boolean | cellSelectionEnabled
Obsolete as of Java 2 platform v1.3. |
| protected TableColumnModel | columnModel
The |
| private boolean | columnSelectionAdjusting
The last value of getValueIsAdjusting from the column selection models columnSelectionChanged notification. |
| protected TableModel | dataModel
The |
| protected transient Hashtable | defaultEditorsByColumnClass
A table of objects that display and edit the contents of a cell,
indexed by class as declared in |
| protected transient Hashtable | defaultRenderersByColumnClass
A table of objects that display the contents of a cell,
indexed by class as declared in |
| private boolean | |
| private transient JTable. | dropLocation
The drop location. |
| private DropMode | dropMode
The drop mode for this component. |
| protected transient int | editingColumn
Identifies the column of the cell being edited. |
| protected transient int | editingRow
Identifies the row of the cell being edited. |
| protected transient Component | editorComp
If editing, the |
| private PropertyChangeListener | |
| private boolean | fillsViewportHeight
Whether or not the table always fills the viewport height. |
| protected Color | gridColor
The color of the grid. |
| private boolean | ignoreSortChange
If true, when sorterChanged is invoked it's value is ignored. |
| private boolean | isRowHeightSet
True when setRowHeight(int) has been invoked. |
| protected Dimension | preferredViewportSize
Used by the |
| private Throwable | printError
To communicate errors between threads during printing. |
| protected int | rowHeight
The height in pixels of each row in the table. |
| protected int | rowMargin
The height in pixels of the margin between the cells in each row. |
| private SizeSequence | |
| private boolean | rowSelectionAdjusting
The last value of getValueIsAdjusting from the row selection models valueChanged notification. |
| protected boolean | rowSelectionAllowed
True if row selection is allowed in this table. |
| protected Color | selectionBackground
The background color of selected cells. |
| protected Color | selectionForeground
The foreground color of selected cells. |
| protected ListSelectionModel | selectionModel
The |
| protected boolean | showHorizontalLines
The table draws horizontal lines between cells if |
| protected boolean | showVerticalLines
The table draws vertical lines between cells if |
| private boolean | sorterChanged
Whether or not sorterChanged has been invoked. |
| private transient JTable. | sortManager
Information used in sorting. |
| private boolean | |
| protected JTableHeader | tableHeader
The |
| private static final String | |
| private transient boolean | updateInProgress
Flag to indicate UI update is in progress |
| private boolean | updateSelectionOnSort
If true, on a sort the selection is reset. |
| Access | Constructor and Description |
|---|---|
| public | JTable()
Constructs a default |
| public | JTable(TableModel
the data model for the table dm)Constructs a |
| public | JTable(TableModel
the data model for the table dm, TableColumnModel the column model for the table cm)Constructs a |
| public | JTable(TableModel
the data model for the table dm, TableColumnModel the column model for the table cm, ListSelectionModel the row selection model for the table sm)Constructs a |
| public | JTable(int
the number of rows the table holds numRows, int the number of columns the table holds numColumns)Constructs a |
| public | |
| public |
| Modifier and Type | Method and Description |
|---|---|
| private void | |
| public void | addColumn(TableColumn
the aColumn)TableColumn to be addedAppends |
| public void | addColumnSelectionInterval(int
one end of the interval index0, int the other end of the interval index1)Adds the columns from |
| public void | addNotify()
Overrides javax. Calls the |
| public void | addRowSelectionInterval(int
one end of the interval index0, int the other end of the interval index1)Adds the rows from |
| private void | |
| private void | |
| private int | |
| private int | |
| public void | changeSelection(int
affects the selection at rowIndex, int rowaffects the selection at columnIndex, boolean columnsee description above toggle, boolean if true, extend the current selection extend)Updates the selection models of the table, depending on the state of the
two flags: |
| private void | changeSelectionModel(ListSelectionModel sm, int index, boolean toggle, boolean extend, boolean selected, int anchor, boolean anchorSelected)
|
| private void | |
| private static void | |
| public void | |
| private void | |
| public void | columnAdded(TableColumnModelEvent e)
Implements javax. Invoked when a column is added to the table column model. |
| public int | Returns: the index of the column thatpoint lies in,
or -1 if the result is not in the range
[0, getColumnCount()-1]the location of interest point)Returns the index of the column that |
| public void | columnMarginChanged(ChangeEvent
the event received e)Implements javax. Invoked when a column is moved due to a margin change. |
| public void | columnMoved(TableColumnModelEvent
the event received e)Implements javax. Invoked when a column is repositioned. |
| public void | columnRemoved(TableColumnModelEvent e)
Implements javax. Invoked when a column is removed from the table column model. |
| public void | columnSelectionChanged(ListSelectionEvent
the event received e)Implements javax. Invoked when the selection model of the |
| pack-priv void | compWriteObjectNotify()
Overrides javax. This is called from Component by way of reflection. |
| protected void | configureEnclosingScrollPane()
If this |
| private void | configureEnclosingScrollPaneUI()
This is a sub-part of configureEnclosingScrollPane() that configures anything on the scrollpane that may change when the look and feel changes. |
| public int | Returns: the index of the corresponding column in the modelthe index of the column in the view viewColumnIndex)Maps the index of the column in the view at
|
| public int | Returns: the index of the corresponding column in the viewthe index of the column in the model modelColumnIndex)Maps the index of the column in the table model at
|
| public int | Returns: the index of the corresponding row in the modelthe index of the row in the view viewRowIndex)Maps the index of the row in terms of the view to the
underlying |
| private int | |
| public int | Returns: the index of the corresponding row in the view, or -1 if the row isn't visiblethe index of the row in terms of the model modelRowIndex)Maps the index of the row in terms of the
|
| private int | convertRowIndexToView(int modelIndex, JTable.
describes the TableModelEvent that initiated the change;
will be null if called as the result of a sort changeConverts a model index to view index. |
| private int[] | |
| protected TableColumnModel | Returns: the default column model objectReturns the default column model object, which is
a |
| public void | createDefaultColumnsFromModel()
Creates default columns for the table from
the data model using the |
| protected TableModel | Returns: the default table model objectReturns the default table model object, which is
a |
| protected void | |
| protected void | createDefaultRenderers()
Creates default cell renderers for objects, numbers, doubles, dates, booleans, and icons. |
| protected ListSelectionModel | Returns: the default selection model objectReturns the default selection model object, which is
a |
| protected JTableHeader | Returns: the default table header objectReturns the default table header object, which is
a |
| public static JScrollPane | Returns: aJScrollPane created using aTablea aTable)JTable to be used for the scroll pane
Deprecated
As of Swing version 1.0.2,
replaced by
new JScrollPane(aTable).
Equivalent to |
| public void | |
| pack-priv JTable. | Returns: the drop location, ornullthe point to calculate a drop location for p)Overrides javax. Calculates a drop location in this component, representing where a drop at the given point should insert data. |
| public boolean | Returns: false if for any reason the cell cannot be edited, or if the indices are invalidthe row to be edited row, int the column to be edited column)Programmatically starts editing the cell at |
| public boolean | Returns: false if for any reason the cell cannot be edited, or if the indices are invalidthe row to be edited row, int the column to be edited column, EventObject event to pass into e)shouldSelectCell;
note that as of Java 2 platform v1.2, the call to
shouldSelectCell is no longer madeProgrammatically starts editing the cell at |
| public void | editingCanceled(ChangeEvent
the event received e)Implements javax. Invoked when editing is canceled. |
| public void | editingStopped(ChangeEvent
the event received e)Implements javax. Invoked when editing is finished. |
| public AccessibleContext | Returns: an AccessibleJTable that serves as the AccessibleContext of this JTableOverrides java. Implements javax. Gets the AccessibleContext associated with this JTable. |
| private int | |
| public boolean | Returns: the autoCreateColumnsFromModel of the tableDetermines whether the table will create default columns from the model. |
| public boolean | Returns: true if aRowSorter should be created when
the model changesReturns |
| public int | Returns: the autoResizeMode of the tableReturns the auto resize mode of the table. |
| public TableCellEditor | Returns: theTableCellEditor that does the editing,
or null if the table is not currently editing.Returns the active cell editor, which is |
| public TableCellEditor | Returns: the editor for this cell; ifnull return the default editor for
this type of cellthe row of the cell to edit, where 0 is the first row row, int the column of the cell to edit,
where 0 is the first column column)Returns an appropriate editor for the cell specified by
|
| public Rectangle | Returns: the rectangle containing the cell at locationrow,columnthe row index where the desired cell
is located row, int the column index where the desired cell
is located in the display; this is not
necessarily the same as the column index
in the data model for the table; the
column, boolean convertColumnIndexToView(int)
method may be used to convert a data
model column index to a display
column indexif false, return the true cell bounds -
computed by subtracting the intercell
spacing from the height and widths of
the column and row models includeSpacing)Returns a rectangle for the cell that lies at the intersection of
|
| public TableCellRenderer | Returns: the assigned renderer; ifnull
returns the default renderer
for this type of objectthe row of the cell to render, where 0 is the first row row, int the column of the cell to render,
where 0 is the first column column)Returns an appropriate renderer for the cell specified by this row and column. |
| public boolean | Returns: true if both row and column selection models are enabledReturns true if both row and column selection models are enabled. |
| public TableColumn | |
| public Class | Returns: the type of the column at positioncolumn
in the view where the first column is column 0the column in the view being queried column)Returns the type of the column appearing in the view at
column position |
| public int | Returns: the number of columns in the tableReturns the number of columns in the column model. |
| public TableColumnModel | Returns: the object that provides the column state of the tableReturns the |
| public String | Returns: the name of the column at positioncolumn
in the view where the first column is column 0the column in the view being queried column)Returns the name of the column appearing in the view at
column position |
| public boolean | Returns: true if columns can be selected, otherwise falseReturns true if columns can be selected. |
| public TableCellEditor | Returns: the default cell editor to be used for this columnClassreturn the default cell editor for this columnClass columnClass)Returns the editor to be used when no editor has been set in
a |
| public TableCellRenderer | Returns: the renderer for this columnClassreturn the default cell renderer
for this columnClass columnClass)Returns the cell renderer to be used when no renderer has been set in
a |
| public boolean | Returns: the value of thedragEnabled propertyReturns whether or not automatic drag handling is enabled. |
| public final JTable. | Returns: the drop locationReturns the location that this component should visually indicate
as the drop location during a DnD operation over the component,
or |
| public final DropMode | |
| public int | Returns: the index of the column that contains the cell currently being edited; returns -1 if nothing being editedReturns the index of the column that contains the cell currently being edited. |
| public int | Returns: the index of the row that contains the cell currently being edited; returns -1 if nothing being editedReturns the index of the row that contains the cell currently being edited. |
| public Component | Returns: Component handling editing sessionReturns the component that is handling the editing session. |
| public boolean | Returns: whether or not this table is always made large enough to fill the height of an enclosing viewportReturns whether or not this table is always made large enough to fill the height of an enclosing viewport. |
| public Color | |
| public Dimension | Returns: the horizontal and vertical spacing between cellsReturns the horizontal and vertical space between cells. |
| private int | |
| private int | |
| public TableModel | Returns: theTableModel that provides the data displayed by this
JTableReturns the |
| private int | getNextBlockIncrement(Rectangle visibleRect, int orientation)
Called to get the block increment for downward scrolling in cases of horizontal scrolling, or for vertical scrolling of a table with variable row heights. |
| public Dimension | Returns: aDimension object containing the preferredSize of the JViewport
which displays this tableImplements javax. Returns the preferred size of the viewport for this table. |
| private int | getPreviousBlockIncrement(Rectangle visibleRect, int orientation)
Called to get the block increment for upward scrolling in cases of horizontal scrolling, or for vertical scrolling of a table with variable row heights. |
| public Printable | Returns: aPrintable for printing this JTablethe printing mode that the printable should use printMode,a headerFormat, MessageFormat MessageFormat specifying the text to
be used in printing a header, or null for nonea footerFormat)MessageFormat specifying the text to
be used in printing a footer, or null for noneReturn a |
| private TableColumn | |
| public int | Returns: the number of rows shown in theJTableReturns the number of rows that can be shown in the
|
| public int | Returns: the height in pixels of a table rowReturns the height of a table row, in pixels. |
| public int | Returns: the height, in pixels, of the cells in the rowthe row whose height is to be returned row)Returns the height, in pixels, of the cells in |
| public int | Returns: the number of pixels between cells in a rowGets the amount of empty space, in pixels, between cells. |
| private SizeSequence | |
| public boolean | Returns: true if rows can be selected, otherwise falseReturns true if rows can be selected. |
| public RowSorter | Returns: the object responsible for sortingReturns the object responsible for sorting. |
| public int | Returns: visibleRect.height or
visibleRect.width
per the orientationImplements javax. Returns |
| public boolean | Returns: false unless getFillsViewportHeight is
true and the table needs to be stretched to fill
the viewportImplements javax. Returns |
| public boolean | Returns: false ifautoResizeMode is set
to AUTO_RESIZE_OFF, otherwise returns trueImplements javax. Returns false if |
| public int | Returns: the "unit" increment for scrolling in the specified directionthe view area visible within the viewport visibleRect, int either orientation, int SwingConstants.VERTICAL
or SwingConstants.HORIZONTALless than zero to scroll up/left,
greater than zero for down/right direction)Implements javax. Returns the scroll increment (in pixels) that completely exposes one new row or column (depending on the orientation). |
| public int | Returns: the index of the first selected columnReturns the index of the first selected column, -1 if no column is selected. |
| public int | Returns: the number of selected columns, 0 if no columns are selectedReturns the number of selected columns. |
| public int[] | Returns: an array of integers containing the indices of all selected columns, or an empty array if no column is selectedReturns the indices of all selected columns. |
| public int | Returns: the index of the first selected rowReturns the index of the first selected row, -1 if no row is selected. |
| public int | Returns: the number of selected rows, 0 if no rows are selectedReturns the number of selected rows. |
| public int[] | Returns: an array of integers containing the indices of all selected rows, or an empty array if no row is selectedReturns the indices of all selected rows. |
| public Color | Returns: theColor used for the background of selected list itemsReturns the background color for selected cells. |
| public Color | Returns: theColor object for the foreground propertyReturns the foreground color for selected cells. |
| public ListSelectionModel | Returns: the object that provides row selection state,null if row
selection is not allowedReturns the |
| public boolean | Returns: true if the table draws horizontal lines between cells, false if it doesn'tReturns true if the table draws horizontal lines between cells, false if it doesn't. |
| public boolean | Returns: true if the table draws vertical lines between cells, false if it doesn'tReturns true if the table draws vertical lines between cells, false if it doesn't. |
| public boolean | Returns: true if the editor should get the focus when keystrokes cause the editor to be activatedReturns true if the editor should get the focus when keystrokes cause the editor to be activated |
| public JTableHeader | Returns: thetableHeader used by this tableReturns the |
| public String | getToolTipText(MouseEvent event)
Overrides javax. Overrides |
| private int | |
| private int | |
| public TableUI | Returns: theTableUI object that renders this componentOverrides javax. Returns the L&F object that renders this component. |
| public String | Returns: the string "TableUI"Overrides javax. Returns the suffix used to construct the name of the L&F class used to render this component. |
| public boolean | Returns: whether to update the selection on a sortReturns true if the selection should be updated after sorting. |
| public Object | Returns: the Object at the specified cellthe row whose value is to be queried row, int the column whose value is to be queried column)Returns the cell value at |
| protected void | |
| public boolean | Returns: true if the cell is editablethe row whose value is to be queried row, int the column whose value is to be queried column)Returns true if the cell at |
| public boolean | Returns: true ifrow and column are valid indices
and the cell at index (row, column) is selected,
where the first row and first column are at index 0the row being queried row, int the column being queried column)Returns true if the specified indices are in the valid range of rows and columns and the cell at the specified position is selected. |
| public boolean | Returns: true ifcolumn is a valid index and the column at
that index is selected (where 0 is the first column)the column in the column model column)Returns true if the specified index is in the valid range of columns, and the column at that index is selected. |
| public boolean | |
| public boolean | Returns: true ifrow is a valid index and the row at
that index is selected (where 0 is the first row)a row in the row model row)Returns true if the specified index is in the valid range of rows, and the row at that index is selected. |
| private static boolean | |
| private int | |
| private int | |
| public void | moveColumn(int
the index of column to be moved column, int the new index of the column targetColumn)Moves the column |
| private void | |
| protected String | Returns: a string representation of this tableOverrides javax. Returns a string representation of this table. |
| public Component | Returns: theComponent being editedthe editor, int TableCellEditor to set upthe row of the cell to edit,
where 0 is the first row row, int the column of the cell to edit,
where 0 is the first column column)Prepares the editor by querying the data model for the value and
selection state of the cell at |
| public Component | Returns: theComponent under the event locationthe renderer, int TableCellRenderer to preparethe row of the cell to render, where 0 is the first row row, int the column of the cell to render,
where 0 is the first column column)Prepares the renderer by querying the data model for the
value and selection state
of the cell at |
| public boolean | Returns: true, unless printing is cancelled by the userA convenience method that displays a printing dialog, and then prints
this |
| public boolean | |
| public boolean | Returns: true, unless printing is cancelled by the userthe printing mode that the printable should use printMode,a headerFormat, MessageFormat MessageFormat specifying the text
to be used in printing a header,
or null for nonea footerFormat)MessageFormat specifying the text
to be used in printing a footer,
or null for noneA convenience method that displays a printing dialog, and then prints
this |
| public boolean | Returns: true, unless printing is cancelled by the userthe printing mode that the printable should use printMode,a headerFormat, MessageFormat MessageFormat specifying the text
to be used in printing a header,
or null for nonea footerFormat, boolean MessageFormat specifying the text
to be used in printing a footer,
or null for nonewhether or not to display a print dialog showPrintDialog, PrintRequestAttributeSet a attr, boolean PrintRequestAttributeSet
specifying any printing attributes,
or null for nonewhether or not to print in an interactive mode interactive)Prints this table, as specified by the fully featured
|
| public boolean | Returns: true, unless printing is cancelled by the userthe printing mode that the printable should use printMode,a headerFormat, MessageFormat MessageFormat specifying the text
to be used in printing a header,
or null for nonea footerFormat, boolean MessageFormat specifying the text
to be used in printing a footer,
or null for nonewhether or not to display a print dialog showPrintDialog, PrintRequestAttributeSet a attr, boolean PrintRequestAttributeSet
specifying any printing attributes,
or null for nonewhether or not to print in an interactive mode interactive, PrintService the destination service)PrintService,
or null to use the default printerPrints this |
| protected boolean | processKeyBinding(KeyStroke ks, KeyEvent e, int condition, boolean pressed)
Overrides javax. Invoked to process the key bindings for |
| private void | readObject(ObjectInputStream s)
Hides javax. We use the |
| public void | removeColumn(TableColumn
the aColumn)TableColumn to be removedRemoves |
| public void | removeColumnSelectionInterval(int
one end of the interval index0, int the other end of the interval index1)Deselects the columns from |
| public void | |
| public void | removeNotify()
Overrides javax. Calls the |
| public void | removeRowSelectionInterval(int
one end of the interval index0, int the other end of the interval index1)Deselects the rows from |
| private void | repaintSortedRows(JTable.
Repaints the sort of sorted rows in response to a TableModelEvent. |
| protected void | |
| private void | restoreSortingEditingRow(int
new index of the editingRow, in terms of the view editingRow)Restores the editing row after a model event/sort order change. |
| private void | restoreSortingSelection(int[] selection, int lead, JTable.
Restores the selection after a model event/sort order changes. |
| public int | Returns: the index of the row thatpoint lies in,
or -1 if the result is not in the range
[0, getRowCount()-1]the location of interest point)Returns the index of the row that |
| public void | |
| private void | |
| private void | |
| public void | setAutoCreateColumnsFromModel(boolean
true if autoCreateColumnsFromModel)JTable should automatically create columnsSets this table's |
| public void | setAutoCreateRowSorter(boolean
whether or not a autoCreateRowSorter)RowSorter
should be automatically createdSpecifies whether a |
| public void | setAutoResizeMode(int
One of 5 legal values:
AUTO_RESIZE_OFF,
AUTO_RESIZE_NEXT_COLUMN,
AUTO_RESIZE_SUBSEQUENT_COLUMNS,
AUTO_RESIZE_LAST_COLUMN,
AUTO_RESIZE_ALL_COLUMNS mode)Sets the table's auto resize mode when the table is resized. |
| public void | |
| public void | setCellSelectionEnabled(boolean
true if simultaneous row and column
selection is allowed cellSelectionEnabled)Sets whether this table allows both a column selection and a row selection to exist simultaneously. |
| public void | setColumnModel(final TableColumnModel
the new data source for this table columnModel)Sets the column model for this table to |
| public void | setColumnSelectionAllowed(boolean
true if this model will allow column selection columnSelectionAllowed)Sets whether the columns in this model can be selected. |
| public void | setColumnSelectionInterval(int
one end of the interval index0, int the other end of the interval index1)Selects the columns from |
| public void | setDefaultEditor(Class<?>
set the default cell editor for this columnClass columnClass, TableCellEditor default cell editor to be used for this columnClass editor)Sets a default cell editor to be used if no editor has been set in
a |
| public void | setDefaultRenderer(Class<?>
set the default cell renderer for this columnClass columnClass, TableCellRenderer default cell renderer to be used for this
columnClass renderer)Sets a default cell renderer to be used if no renderer has been set in
a |
| public void | setDragEnabled(boolean
whether or not to enable automatic drag handling b)Turns on or off automatic drag handling. |
| pack-priv Object | Returns: any saved state for this component, ornull if nonethe drop location (as calculated by
location,dropLocationForPoint) or null
if there's no longer a valid drop locationthe state object saved earlier for this component,
or state, boolean nullwhether or not the method is being called because an
actual drop occurred forDrop)Overrides javax. Called to set or clear the drop location during a DnD operation. |
| public final void | |
| public void | |
| public void | |
| public void | setFillsViewportHeight(boolean
whether or not this table is always
made large enough to fill the height of an enclosing
viewport fillsViewportHeight)Sets whether or not this table is always made large enough to fill the height of an enclosing viewport. |
| public void | setGridColor(Color
the new color of the grid lines gridColor)Sets the color used to draw grid lines to |
| public void | setIntercellSpacing(Dimension
a intercellSpacing)Dimension
specifying the new width
and height between cellsSets the |
| public void | setModel(final TableModel
the new data source for this table dataModel)Sets the data model for this table to |
| public void | setPreferredScrollableViewportSize(Dimension
a size)Dimension object specifying the preferredSize of a
JViewport whose view is this tableSets the preferred size of the viewport for this table. |
| public void | setRowHeight(int
new row height rowHeight)Sets the height, in pixels, of all cells to |
| public void | setRowHeight(int
the row whose height is being
changed row, int new row height, in pixels rowHeight)Sets the height for |
| public void | setRowMargin(int
the number of pixels between cells in a row rowMargin)Sets the amount of empty space between cells in adjacent rows. |
| public void | setRowSelectionAllowed(boolean
true if this model will allow row selection rowSelectionAllowed)Sets whether the rows in this model can be selected. |
| public void | setRowSelectionInterval(int
one end of the interval index0, int the other end of the interval index1)Selects the rows from |
| public void | setRowSorter(RowSorter<? extends TableModel>
the sorter)RowSorter; null turns
sorting offSets the |
| public void | setSelectionBackground(Color
the selectionBackground)Color to use for the background
of selected cellsSets the background color for selected cells. |
| public void | setSelectionForeground(Color
the selectionForeground)Color to use in the foreground
for selected list itemsSets the foreground color for selected cells. |
| public void | setSelectionMode(int
the mode used by the row and column selection models selectionMode)Sets the table's selection mode to allow only single selections, a single contiguous interval, or multiple intervals. |
| public void | setSelectionModel(final ListSelectionModel
the new selection model selectionModel)Sets the row selection model for this table to |
| public void | setShowGrid(boolean
true if table view should draw grid lines showGrid)Sets whether the table draws grid lines around cells. |
| public void | setShowHorizontalLines(boolean
true if table view should draw horizontal lines showHorizontalLines)Sets whether the table draws horizontal lines between cells. |
| public void | setShowVerticalLines(boolean
true if table view should draw vertical lines showVerticalLines)Sets whether the table draws vertical lines between cells. |
| public void | setSurrendersFocusOnKeystroke(boolean
true if the editor should get the focus
when keystrokes cause the editor to be
activated surrendersFocusOnKeystroke)Sets whether editors in this JTable get the keyboard focus when an editor is activated as a result of the JTable forwarding keyboard events for a cell. |
| public void | setTableHeader(JTableHeader
new tableHeader tableHeader)Sets the |
| public void | |
| pack-priv void | |
| public void | setUpdateSelectionOnSort(boolean
whether or not to update the selection on sorting update)Specifies whether the selection should be updated after sorting. |
| public void | setValueAt(Object
the new value aValue, int the row of the cell to be changed row, int the column of the cell to be changed column)Sets the value for the cell in the table model at |
| private void | |
| public void | sizeColumnsToFit(boolean
determines whether to resize last column only lastColumnOnly)
Deprecated
As of Swing version 1.0.3,
replaced by
doLayout().
Sizes the table columns to fit the available space. |
| public void | sizeColumnsToFit(int
the column whose resizing made this adjustment
necessary or -1 if there is no such column resizingColumn)Obsolete as of Java 2 platform v1.4. |
| private void | sortedTableChanged(RowSorterEvent sortedEvent, TableModelEvent e)
Invoked when |
| public void | sorterChanged(RowSorterEvent
the e)RowSorterEvent describing the changeImplements javax.
|
| public void | tableChanged(TableModelEvent e)
Implements javax. Invoked when this table's |
| private void | |
| private void | |
| private int | |
| protected void | unconfigureEnclosingScrollPane()
Reverses the effect of |
| public void | updateUI()
Overrides javax. Notification from the |
| public void | valueChanged(ListSelectionEvent
the event received e)Implements javax. Invoked when the row selection changes -- repaints to show the new selection. |
| private int | |
| private void | writeObject(ObjectOutputStream s)
Hides javax. See readObject() and writeObject() in JComponent for more information about serialization in Swing. |