4


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.

brian_d
  • 11,190
  • 5
  • 47
  • 72

2 Answers2

3

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

trashgod
  • 203,806
  • 29
  • 246
  • 1,045
dogbane
  • 266,786
  • 75
  • 396
  • 414
  • 1
    Seems that this example is referenced a lot on other forums and http://stackoverflow.com/questions/476721/merging-cells-in-jtable as well. However, I am leery about using independent code from 1998 which was tested on Swing1.1beta3 – brian_d Nov 10 '10 at 19:13
  • It's not the answer I had hoped for, but it seems that this is the current state of JTable (ie. not much progress since it's inception). I'll accept your answer, but stick with XHTMLRenderer. – brian_d Nov 17 '10 at 18:18
  • The link in this answer is broken. I think [this answer](http://stackoverflow.com/a/21977825/878469) links a working one, in addition to explaining a necessary fix for it. – predi May 31 '16 at 08:40
1

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.

Geoffrey Zheng
  • 6,562
  • 2
  • 38
  • 47