brian_d
brian_d

Reputation: 11395

JTable with varying number of columns per row


how can I get a JTable to layout some rows with just one column like:

A1 Section Title Row With long Text
A2          B2          C2          D2
A3          B3          C3          D3
A4          B4          C4          D4
A5 Section Title Row With long Text
A6          B6          C6          D6
A7 Section Title Row With long Text
A8          B8          C8          D8
A9          B9          C9          D9

instead of

A1 Section Title Row With long Text  B1          C1          D1
A2                                   B2          C2          D2
A3                                   B3          C3          D3
A4                                   B4          C4          D4
A5 Section Title Row With long Text  B5          C5          D5
A6                                   B6          C6          D6
A7 Section Title Row With long Text  B7          C7          D7
A8                                   B8          C8          D8
A9                                   B9          C9          D9

I have done this type of layout using xhtmlrenderer but am wondering if it is possible to change the individual cell span of a JTable. Thanks.

Upvotes: 4

Views: 1877

Answers (2)

dogbane
dogbane

Reputation: 274778

Take a look at this example which shows how you can "merge cells" in a JTable.

Upvotes: 3

Geoffrey Zheng
Geoffrey Zheng

Reputation: 6638

The commercial JIDE Grids has CellSpanTable and GroupTable. The basic idea is the same as that ancient code in @dogbane's answer, which is to use a custom UI that doesn't draw grid lines for spanned cells.

Upvotes: 1

Related Questions