What you're looking for is a # (compare to column header , used when you want a line fixed at the top). There is a similar question in StackOverflow in English, but the answers do not contain much information, only dois links .
I took a quick look at the two of them, and they split the JTable
into two ... However, the first link allows you to use a single TableModel
for both tables - which is what really matters, right?
See the link to the complete solution. Example of use (simplified):
TableModel data = new DefaultTableModel(0,10); // Substitua com seu TableModel particular
// Criando o modelo de coluna para a tabela "normal" (coluna 1 em diante)
TableColumnModel columns = new DefaultTableColumnModel();
for (int count = data.getColumnCount(), i = 1; i < count; i++)
{
TableColumn c = new TableColumn(i);
c.setHeaderValue(data.getColumnName(i));
columns.addColumn(c);
}
// Criando o modelo de coluna para o cabeçalho (coluna 0; se quiser pode fixar mais colunas)
TableColumnModel headerColumns = new DefaultTableColumnModel();
TableColumn h = new TableColumn(0);
h.setHeaderValue(data.getColumnName(0));
headerColumns.add(h);
// Criando as tabelas
JTable table = new JTable(data, columns);
JTable rowHeader = new JTable(data, headerColumns);
// RowHeaderRendered é uma classe externa, que pode ser baixada no link acima
rowHeader.setDefaultRenderer(Object.class, new RowHeaderRenderer());
JScrollPane scrollPane = new JScrollPane(table);
scrollPane.setRowHeaderView(rowHeader);