如何在DefaultTableModel / JTable中合并单元格? [英] How to merge cell in DefaultTableModel/JTable?

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

问题描述

我搜索了很多并得到了这个Q的答案。但是他们中的许多人都提到了404错误的链接。
我想制作这样的表:





java中有没有这方法?

解决方案

,遗憾的是它不是免费的。这是例如 CellSpanTable




I searched a lot and got some answers for this Q. but many of them referred to links which give 404 error. I want to make table like this:

Is there any method in java for this?

解决方案

MultiSpanCellTableExample demonstrates how to merge cells by creating a custom TableUI. There seem to be a problem in this example that causes StackOverflowError, at least in Java 6. To fix this, inside AttributiveCellTableModel.setDataVector() replace:

setColumnIdentifiers(columnNames);

with:

this.columnIdentifiers = columnNames;

IE:

public void setDataVector(Vector newData, Vector columnNames) {
    if (newData == null)
        throw new IllegalArgumentException(
                "setDataVector() - Null parameter");
    dataVector = new Vector(0);
    // setColumnIdentifiers(columnNames);
    this.columnIdentifiers = columnNames;
    dataVector = newData;

    cellAtt = new DefaultCellAttribute(dataVector.size(),
            columnIdentifiers.size());

    newRowsAdded(new TableModelEvent(this, 0, getRowCount() - 1,
            TableModelEvent.ALL_COLUMNS, TableModelEvent.INSERT));
}

The problem is that setColumnIdentifiers calls into setDataVector hence triggering the StackOverflowError. Once fixed, this is how the example looks like:

There is also a ready solution from JIDE, unfortunately it is not free. Here is for example CellSpanTable:

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

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