【问题标题】:JTable with varying number of columns per row每行具有不同列数的 JTable
【发布时间】:2011-05-08 01:33:27
【问题描述】:


我怎样才能让 JTable 用一列来布局一些行,例如:

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

而不是

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

我已经使用 xhtmlrenderer 完成了这种类型的布局,但我想知道是否可以更改 JTable 的单个单元格跨度。 谢谢。

【问题讨论】:

    标签: java swing jtable tablelayout


    【解决方案1】:

    看看this example,它展示了如何在 JTable 中“合并单元格”。

    【讨论】:

    • 似乎这个例子在其他论坛和stackoverflow.com/questions/476721/merging-cells-in-jtable 上被引用了很多。但是,我对使用 1998 年在 Swing1.1beta3 上测试过的独立代码持怀疑态度
    • 这不是我所希望的答案,但似乎这是 JTable 的当前状态(即,自成立以来没有太大进展)。我会接受你的回答,但坚持使用 XHTMLRenderer。
    • 此答案中的链接已损坏。我认为this answer 链接了一个有效的,除了解释一个必要的修复它。
    【解决方案2】:

    广告JIDE Grids 有CellSpanTable 和GroupTable。基本思想与@dogbane 答案中的古老代码相同,即使用不会为跨单元格绘制网格线的自定义 UI。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-01-07
      • 1970-01-01
      • 2015-07-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多