JTable with varying number of columns per row

左心房为你撑大大i 提交于 2019-12-12 12:18:31

问题



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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!