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

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 ...

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