我正在尝试在 Jtable 中执行嵌套标题,就像在http://www.esus.com/docs/GetQuestionPage.jsp?uid=1272中一样, 但这不起作用。
这是我尝试使用来自http://www.esus.com/docs/GetQuestionPage.jsp?uid=1272的类的代码:
DefaultTableModel tableModel = new DefaultTableModel();
tableModel.setDataVector(
new Object[][]{},
new String[]{
"Klient", "Numer dokumentu", "E2", "Jedn.", "EUR", "H1", "E2", "Jedn.", "EUR", "H1"
});
JTable jTable1 = new javax.swing.JTable(tableModel) {
@Override
protected JTableHeader createDefaultTableHeader() {
return new GroupableTableHeader(columnModel);
}
};
TableColumnModel cm = jTable1.getColumnModel();
ColumnGroup documentGroup = new ColumnGroup("Dokumenty");
ColumnGroup sendedGroup = new ColumnGroup("Wysłane");
ColumnGroup returnedGroup = new ColumnGroup("Zwracane");
documentGroup.add(cm.getColumn(0));
documentGroup.add(cm.getColumn(1));
sendedGroup.add(cm.getColumn(2));
sendedGroup.add(cm.getColumn(3));
sendedGroup.add(cm.getColumn(4));
sendedGroup.add(cm.getColumn(5));
returnedGroup.add(cm.getColumn(6));
returnedGroup.add(cm.getColumn(7));
returnedGroup.add(cm.getColumn(8));
returnedGroup.add(cm.getColumn(9));
GroupableTableHeader header = (GroupableTableHeader) jTable1.getTableHeader();
header.addColumnGroup(documentGroup);
header.addColumnGroup(sendedGroup);
header.addColumnGroup(returnedGroup);
jScrollPane1.setViewportView(jTable1);