JTable中的页脚行

Luk*_*ane 5 java swing jtable

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

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


这是我最终得到的:

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);
Run Code Online (Sandbox Code Playgroud)

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

obj*_*cts 5

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

JTable footer = new JTable(model, table.getColumnModel());
panel.add(BorderLayout.CENTER, table);
panel.add(BorderLayout.SOUTH, footer);
Run Code Online (Sandbox Code Playgroud)

  • 这基本上看起来是一个很好的解决方案,但是当您尝试调整列的大小时,它似乎反应非常奇怪. (3认同)