It is important that more than 1 line is displayed in a cell. To do this, I wrote class MultiLineCellRenderer that extends JTextArea and implements TableCellRenderer (solution I found on the Internet).
Then I realised that the cells should not be editable. For this, I wrote class MyTableModel that extends AbstractTableModel (again, solution from the Internet).
So I apllied both to the table, like this:
table.setModel(new MyTableModel(data, columnNames));
table.setDefaultRenderer(String.class, new MultiLineCellRenderer());
The problem: It looks like I can use either one or the other. If I use the renderer for my table, multiple lines are shown in cells, but the cells are editable. If I use the table model, or both, then the cells are not editable, but only 1 line is displayed in each cell :-/
Any suggestions? Can the renderer and the table model be used together?
Can the renderer and the table model be used together?
Yes.
For this, I wrote class MyTableModel that extends AbstractTableModel (again, solution from the Internet).
There is no need to create a new TableModel for this. You can extend the DefaultTableModel and override the isCellEditable(...) method. Or you can extend JTable and do the same.
Did you also override the getColumnClass() method of the TableModel? The default is to return Object, so your renderer would never be used.
If you need more help then post your SSCCE that demonstrates the problem because we can't keep guessing what you custom code may or may not look like.