im coding soft that uses table and jtable gives me hard time again.
for single row header im using:
private class make_table extends AbstractTableModel {
private String[] headers = headers();
Object[][] rows = rows();
public int getColumnCount() {
return headers.length;
}
public int getRowCount() {
return rows.length;
}
public String getColumnName(int col) {
return headers[col];
}
public Object getValueAt(int row, int col) {
return rows[row][col];
}
public Class getColumnClass(int c) {
return getValueAt(0, c).getClass();
}
}
then i just pass it into:
table = new JTable(new make_table());
headers(); method just returns String[] with names of columns - 1 dimensional array.
i've tried to make headers() retrun 2D array - String[][] and headers within make_table String[][] instead of String[]. my problem is how to render it/show it in JTable.
i've just copy-pasted that whole method long time ago into another project and i cant understand how it works. i guess i could somehow use way im handling rows since its 2D array but i cant get my head around it.
note: i've read some stuff but it all seems to be focusing on not same number of cells in row 1 and row 2. i want first row header to have 6 cells and second row in header 6 cells as well.
my question: how could i pass into & show two row header JTable? preferably via 2D array.
Two different approaches:
<br>tag to denote each lineIn both cases the height of the column header will be determined the the number of lines in the first column: