The JTable Class

Well, we made it this far without officially discussing the JTable class itself. Dynamic data and database queries are all handled entirely by the table model underneath the display. So what can you do with a JTable object? The JTable class gives you control over the appearance and behavior of the table. You can control the spacing of columns, their resizability, their colors, and so on. The JTable object will be the source of row selections, and through delegation, you can add and remove rows and columns directly with the JTable object.

Properties

The appearance of a JTable is manipulated almost entirely through its properties. To make things a bit more manageable, we’ll break the properties up into three smaller tables: one for row, column and cell properties; one for selection properties; and one for the visual properties. Table 15.9 covers the row, column, and cell properties.

Table 15-9. JTable Row, Column, and Cell Properties

Property

Data Type

get

is

set

bound

Default Value

columnModel

TableColumnModel

•

 

•

 

DefaultTableColumnModel()

model

TableModel

•

 

•

 

DefaultTableModel()

autoCreateColumnsFromModel

boolean

•

 

•

 

false

autoResizeMode

int

•

 

•

 

AUTO_RESIZE_ALL_COLUMNS

columnCount*

int

•

   

0

rowCount*

int

•

   

0

rowHeight

int

•

 

•

 

16

The autoCreateColumnsFromModel property determines whether or not the column model ...

Get Java Swing now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.