Java Reference
In-Depth Information
It's the responsibility of the current
ListSelectionModel
settings to control the selection within
a table.
The display of the different cells within a table is the responsibility of the
TableCellRenderer
;
the
DefaultCellRenderer
offers one such implementation of the
TableCellRenderer
interface
in a
JLabel
subclass.
Managing the data stored in the cells is accomplished through an implementation of the
TableModel
interface. The
AbstractTableModel
provides the basics of an implementation of the
interface without any data storage. By comparison, the
DefaultTableModel
encapsulates the
TableModel
interface and uses a
Vector
of
Vector
objects for the data storage. You extend
AbstractTableModel
if you need a different type of storage than the kind supplied by the
DefaultTableModel
; for instance, if you already had the data in your own data structure.
The
TableColumnModel
interface and the
DefaultTableColumnModel
implementation of the
interface manage the table's data as a series of columns. They work together with the
TableColumn
class to allow for greater flexibility in manipulating individual columns. For example, you can
store columns of data in the
TableModel
in an order that's different from the display order within
the
JTable
. The
TableColumnModel
manages a second
ListSelectionModel
to control table
column selection.
At the top of every column is a column header. By default, the
TableColumn
class relies on
the
JTableHeader
class to render a text column header. Nevertheless, you must embed the
JTable
in a scroll pane to see the default header.
Cells within a
JTable
can be editable. If a cell is editable, how the editing works depends on
the
TableCellEditor
implementation, such as the
DefaultCellEditor
implementation, which
extends from
AbstractCellEditor
. In addition, no classes exist to handle individual rows. Rows
must be manipulated on a cell-by-cell basis. Behind the scenes, the
JTable
uses the
SizeSequence
utility class to deal with variable height rows; you won't need to manipulate it yourself.
There are additional interrelationships among the elements used by the
JTable
component.
These relationships will be explored later in this chapter with each specific interface and class.
To visualize how the
JTable
elements all fit together, examine Figure 18-2.
,IST3ELECTION-ODEL
*4ABLE(EADER
4ABLE-ODEL
4ABLE#ELL%DITOR
4ABLE#ELL2ENDERER
%VERY#ELL
4ABLE#OLUMN
4ABLE#OLUMN-ODEL
3ETOF4ABLE#OLUMN/BJECTS
Figure 18-2.
JTable elements