问题
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.
回答1:
Take a look at this example which shows how you can "merge cells" in a JTable.
回答2:
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.
来源:https://stackoverflow.com/questions/4147843/jtable-with-varying-number-of-columns-per-row