JTable单元跨度合并(JTable cell span merge)

编程入门 行业动态 更新时间:2024-10-27 12:32:12
JTable单元跨度合并(JTable cell span merge)

嗨,我遇到了Java JTable的问题。 我想合并或跨越细胞。 我用这个例子做到了:

http://www.java3z.com/cwbwebhome/article/article5/swing_example/JTableExamples4.html (最后2个)

它工作但标题和单元格宽度不同。 当有20列以上时,问题就会出现问题,最后一个单元只出现一半。 有谁知道如何解决同步单元格和标题的问题? 有没有人有另一个CellSpan示例/方式?

如果有人试图运行这个例子会得到StackOverFlow错误,要解决,只需改变这一行: setColumnIdentifiers(columnNames); to columnIdentifiers = columnNames; 在AttributiveCellTableModel类。 提前致谢!!

Hi I'm having a problem with Java JTable. I want to merge or span cells. I did it using this examples:

http://www.java3z.com/cwbwebhome/article/article5/swing_example/JTableExamples4.html (last 2 ones)

It works but the header and the cells width are not the same size. The problem agravates when there are more 20 columns, the last cells appear just half. Does anyone know how to solve this problem of synchronizing cells and headers? Does anyone have another CellSpan example/way?

If someone try to run this examples will get StackOverFlow error,to solve, justo change this line: setColumnIdentifiers(columnNames); to columnIdentifiers = columnNames; at AttributiveCellTableModel class. Thanks in Advance!!

最满意答案

这里有相同的例子。 似乎问题可能出在MultiSpanCellTable getCellRect()实现中。 列边距有助于单元格宽度并生成此偏移。 看起来如果你更换问题就会消失:

cellFrame.width = aColumn.getWidth() + columnMargin;

有:

cellFrame.width = aColumn.getWidth();

The same example is available here. It seems the problem might be in MultiSpanCellTable getCellRect() implementation. Column margin is contributing to the cell width and generating this offset. Looks like the problem goes away if you replace:

cellFrame.width = aColumn.getWidth() + columnMargin;

with:

cellFrame.width = aColumn.getWidth();

更多推荐

本文发布于:2023-07-26 19:21:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1279863.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:跨度   单元   JTable   merge   span

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!