JTable中的页脚行 [英] Footer row in a JTable

查看:72
本文介绍了JTable中的页脚行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

将页脚行放入JTable的最佳方法是什么?有没有人有任何示例代码来执行此操作?

What is the best way to put a footer row into a JTable? Does anyone have any sample code to do this?

到目前为止,我唯一想到的方法是在表模型中放一个特殊的行,它总是被排序到底部。

The only approach I've thought of so far is to put a special row into the table model that always get sorted to the bottom.

以下是我最终的结果:

JTable mainTable = new JTable(mainTableModel);
JTable footerTable = new JTable(footerModel);
footerTable.setColumnModel(mainTable.getColumnModel());

// Disable selection in the footer. Otherwise you can select the footer row
// along with a row in the table and that can look quite strange.
footerTable.setRowSelectionAllowed(false);
footerTable.setColumnSelectionAllowed(false);

JPanel tablePanel = new JPanel();
BoxLayout boxLayout = new BoxLayout(tablePanel, BoxLayout.Y_AXIS);
tablePanel.setLayout(boxLayout);
tablePanel.add(mainTable.getTableHeader()); // This seems like a bit of a WTF
tablePanel.add(mainTable);
tablePanel.add(footerTable);

排序工作正常,但选择页脚行有点奇怪。

Sorting works fine but selecting the footer row is a bit strange.

推荐答案

尝试使用与数据表使用相同列模型的第二个JTable,并将页脚数据添加到该表。在原始表下添加第二个(页脚)表。

Try using a second JTable that uses the same column model as your data table and add your footer data to that table. Add the second (footer) table under your original table.

JTable footer = new JTable(model, table.getColumnModel());
panel.add(BorderLayout.CENTER, table);
panel.add(BorderLayout.SOUTH, footer);

这篇关于JTable中的页脚行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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