O'Reilly logo

Java Swing by Dave Wood, Marc Loy, Robert Eckstein

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Table Data

We’ve seen the TableColumnModel which stores a lot of information about the structure of a table, but doesn’t contain the actual data. The data that’s displayed in a JTable is stored in a TableModel. The TableModel interface describes the minimum requirements for a model that supplies the information necessary to display and edit a table’s cells, and to show column headers. The AbstractTableModel fills out most of the TableModel interface, but leaves the methods for retrieving the actual data undefined. The DefaultTableModel extends AbstractTableModel and provides an implementation for storing data as a vector of vectors. We’ll be looking at both the abstract and default table models in more detail later in this chapter.

The TableModel Interface

All of the table models start with this interface. A table model must be able to give out information on the number of rows and columns in the table and have access to the values of the cells of the table. The TableModel interface also has methods that can be used to encode information about the columns of the table (such as a localized name or class type), apart from the column model.

Properties

The TableModel interface supports the properties shown in Table 15.5. The columnCount is the number of columns in the data model. This does not have to match the number of columns reported by the column model. Likewise, rowCount is the number of rows in the data model. columnName and columnClass are indexed properties that let you ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required