JTable单元跨度合并 [英] JTable cell span merge

查看:109
本文介绍了JTable单元跨度合并的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好,我遇到了Java JTable的问题。我想合并或跨越单元格。我使用这个例子做了:

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



它可以工作,但标题和单元格宽度不一样大小。如果有更多的20列,问题就会恶化,最后的单元只出现一半。有谁知道如何解决同步单元和标题的这个问题?有人有另一个CellSpan的例子/方式?如果有人试图运行这个例子将得到StackOverFlow错误,解决,只是改变这一行: setColumnIdentifiers(columnNames ); 到AttributiveCellTableModel类的 columnIdentifiers = columnNames; 。提前致谢!

代码/ Java / Swing-Components / MultiSpanCellTableExample.htmrel =nofollow>这里。看来问题可能出自 MultiSpanCellTable getCellRect()实现。列边距有助于单元格宽度并生成此偏移量。如果您替换,看起来问题会消失:

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

附带:

  cellFrame.width = aColumn.getWidth(); 


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!!

解决方案

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();

这篇关于JTable单元跨度合并的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆