I have JTable
added on panel and I need it to have grouped columns. I Implemented the known solutions given here but something is wrong with my code, table is not shown.
Here is the code:
public void createTable(){
DefaultTableModel dm = new DefaultTableModel();
dm.setDataVector(new Object[][]{
{"119","foo","bar","ja","ko","zh"},
{"911","bar","foo","en","fr","pt"}},
new Object[]{"SNo.","1","2","Native","2","3"});
table = new JTable( dm ) {
protected JTableHeader createDefaultTableHeader() {
return new GroupableTableHeader(columnModel);
}
};
TableColumnModel cm = table.getColumnModel();
ColumnGroup g1 = new ColumnGroup("Group 1");
g1.add(cm.getColumn(1));
g1.add(cm.getColumn(2));
ColumnGroup g2 = new ColumnGroup("Group 2");
g2.add(cm.getColumn(3));
g2.add(cm.getColumn(4));
GroupableTableHeader header = (GroupableTableHeader)table.getTableHeader();
header.addColumnGroup(g1);
header.addColumnGroup(g2);
}