合并 JTable 中的单元格

发布于 2024-07-13 05:55:13 字数 338 浏览 3 评论 0原文

是否可以合并 JTable 对象的某些单元格?

合并单元格
(来源:codeguru.com

如果是不可能通过 JTable 什么是最好的方法。 谢谢。

Is it possible to merge some cells of a JTable object?

merging cells
(source: codeguru.com)

If it's not possible through JTable what is the best approach. Thanks.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

鲜肉鲜肉永远不皱 2024-07-20 05:55:14

您可以使用 TableModel 合并原始 TableModel 的两列来实现 JTable。

class Model2 extends AbstractTableModel
{
private TableModel delegate;
public Model2(TableModel delegate)
 {
 this.delegate= delegate;
 }

public int getRowCount() { return this.delegate.getRowCount();}
public int getColumnCount() { return this.delegate.getColumnCount()-1;}
public Object getValueAt(int row, int col)
 {
 if(col==0) return ""+delegate.getValueAt(row,col)+delegate.getValueAt(row,col+1);
 return delegate.getValueAt(col+1);
 }
(...)
}

You could implement a JTable using a TableModel merging two columns of the original TableModel.

class Model2 extends AbstractTableModel
{
private TableModel delegate;
public Model2(TableModel delegate)
 {
 this.delegate= delegate;
 }

public int getRowCount() { return this.delegate.getRowCount();}
public int getColumnCount() { return this.delegate.getColumnCount()-1;}
public Object getValueAt(int row, int col)
 {
 if(col==0) return ""+delegate.getValueAt(row,col)+delegate.getValueAt(row,col+1);
 return delegate.getValueAt(col+1);
 }
(...)
}
篱下浅笙歌 2024-07-20 05:55:14

不是开箱即用的。 这里是一个支持合并任意单元格的示例此页面有几个带有跨单元格的表格示例。 当然,它已经很旧了,而且一分钱一分货。 如果可以选择付费软件,JIDE Grids 有一些非常好的 Swing 表支持包括自定义单元格跨度

Not out-of-the-box. Here is an example that supports merging arbitrarty cells. This page has several examples of tables with spanning cells. Of course it's old and you get what you pay for. If paid software is an option, JIDE Grids has some really nice Swing table support including custom cell spans.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文